Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date formatter doesn't show up properly when using multiple bars in a chart. #2030

Closed
micmar opened this issue Jan 2, 2017 · 7 comments
Closed

Comments

@micmar
Copy link

micmar commented Jan 2, 2017

Premise: it was all working nicely before version 3, where NSFormatters are used for X axis.
I have a BarChartView where the X axis formatter is a DateValueFormatter (as nicely provided in demo code).
I am looking at demo code MultipleBarChartViewController.m, but unfortunately there years are integer, not date, which is where I get the problem.

In my case, the BarChartViewhas two different BarChartDataSet and at this point the dates in X axis are confused and they are only half of what they should be.
For example if it is supposed to go from 1st December to 31st December, it goes only from 1st to 15th of December, spread in the whole axis.

Hopefully the attachment helps to understand the problem.
(It is supposed to go from 1st to 31st).

Does anyone see this? Is this a bug or did I implement it wrongly?

Keep up the great work!
Mik

screen shot 2017-01-02 at 21 46 57

@liuxuan30
Copy link
Member

You have 27 entries for each data set? What's the last entry x value? It seems like it's your setup problem. The label is not centered properly.

Check out have you set group space, bar width properly.

    float groupSpace = 0.08f;
    float barSpace = 0.03f;
    float barWidth = 0.2f;
    // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"

make sure the sum is 1.0 to test.

@micmar
Copy link
Author

micmar commented Jan 3, 2017

Dear liuxuan30,

thanks for assisting.
I am quite sorry but I don't get it...
what is it the number 4 in here?
// (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
And is it always supposed to be equal to one?

Regarding your questions:

  1. yes, in this graph - which is a month span - I do have 27 entries for each data set (one per day except than Sundays).

  2. Values are date divided by 86400
    double timeVal = [obj.time timeIntervalSince1970]/86400;

and in the data formatter::stringForValue that is taken into account:
return [_dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:(value*86400)]];
All this just to make the bars visible in that time span.

  1. First value is 17135.958333
    Last value is 17165.958333

  2. with your settings I get exactly the graph I posted:
    float groupSpace = 0.08f;
    float barSpace = 0.03f;
    float barWidth = 0.2f;

    data.barWidth = barWidth;

//xMin is first value
_chartView.xAxis.axisMinimum = xMin;

//totalItems is the number of data in each data set (27 in this case)
_chartView.xAxis.axisMaximum = xMin + [data groupWidthWithGroupSpace:groupSpace barSpace: barSpace] * (totalItems);

[data groupBarsFromX: xMin groupSpace: groupSpace barSpace: barSpace];

Any hint? Thanks again!

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 4, 2017

Sorry, '4' should mean the count of data sets in ChartsDemo. What I meant is you can check ChartsDemo - multiple bar chart as example. I remember it's supposed to be 1.0, someone mentioned it in the past.

I just saw your labels are not centered properly, so things might goes wrong.

I notice your data is all displayed, however the x axis labels does not match. Can you check your formatter? e.g. When it formats to "15. Dec", what's the original value for it? Ideally, the last label should be in a small delta from Last value is 17165.958333 If "15.Dec"'s original value is like 17150, then the problem would be your value is too big, then you need to check computeAxisValues() for x axis to see how it calculates axis.entries. You need to post what axis.entries are, so we know the full original values.

BTW, if you just want to show single days, why not use [1,30] as your x values?

@micmar
Copy link
Author

micmar commented Jan 4, 2017

Thank you so much liuxuan!

The key was understanding that I didn't have to use '4' but '2' in the equation, meaning to understand that that was the number of data sets.

Regarding to your other point/suggestion I cannot use [1,30] as x values because different graphs have different data ranges (like 3 months for example) and labels have to be adjusted accordingly.
Now it seems it all works.

Thanks a lot again!

@liuxuan30
Copy link
Member

@micmar what make it work then? correcting to the right data sets count?

@micmar
Copy link
Author

micmar commented Jan 6, 2017

Exactly: as I said using '2' (I have two data sets) rather than '4' in the equation, made it work.

@liuxuan30
Copy link
Member

ok, cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants