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

Gap issues on latest version #804

Closed
acegreen opened this issue Mar 6, 2016 · 23 comments
Closed

Gap issues on latest version #804

acegreen opened this issue Mar 6, 2016 · 23 comments

Comments

@acegreen
Copy link

acegreen commented Mar 6, 2016

Hello,

I'll start off by saving, great work on this library, I have been using it for a while now with no issues. I came across something interesting with the new update.

  1. Gap between bars and bottom axis with a barChart
    As I recall, this gap was not present before. You can see in the image below, there is a gap between the bars and the bottom line

simulator screen shot mar 6 2016 9 10 54 am

@liuxuan30
Copy link
Member

Latest release has deprecated startAtZeroEnabled, which seems is your case.
Please try set customAxisMax and customAxisMin to get the expcted range. e.g.

leftAxis.customAxisMin = 0.0; // this replaces startAtZero = YES

I used ChartsDemo, and the 0-yaxis still at the bottom

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

@liuxuan30 Yea startAtZeroEnabled but by default .customAxisMin = 0.0 anyway. Still getting that gap though

@liuxuan30
Copy link
Member

@danielgindi This question has been asked twice (another is from SO:http://stackoverflow.com/questions/35798915/issue-in-display-of-barchart-with-latest-ioscharts)

I debugged a little with ChartsDemo:
Reproduce code, just to insert a small value to stablely trigger it:

        double val =  (double) (arc4random_uniform(mult));
        if (i == 0)
            [yVals addObject:[[BarChartDataEntry alloc] initWithValue:1 xIndex:i]];
        else
            [yVals addObject:[[BarChartDataEntry alloc] initWithValue:val xIndex:i]];

and in calcMinMax line 337:

        // Use the values as they are
        _leftAxis.axisMinimum = !isnan(_leftAxis.customAxisMin)
            ? _leftAxis.customAxisMin
            : (minLeft - bottomSpaceLeft)

at this moment, my minLeft is 1.0, while bottomSpaceLeft is 3.5 (35 * 0.1), so the axisMinimum < 0, and we see the additional space.
so when leftRange * Double(_leftAxis.spaceBottom) is larger than minLeft, we can always reproduce it.
Shall we force axisMinimum to 0 if customAxisMin is NaN?

@liuxuan30
Copy link
Member

@acegreen could you specificly call

leftAxis.customAxisMin = 0.0; // this replaces startAtZero = YES
or leftAxis.startAtZeroEnabled = YES;

on left or right axis? (if you are using both, call on each axis)
I tried with ChartsDemo, when I call them, the gap is gone.

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

Its always nice to link to a SO question where the only answer is

If you still cannot get the y axis bottom as 0, please file a bug on github page

I also already tried to specify leftAxis.customAxisMin = 0.0 and leftAxis.startAtZeroEnabled = YES with no effect.

My data sets are on the xAxis in my case so it also make sense that the left or right axis are irrelevant

@liuxuan30
Copy link
Member

hmm, could you try add break point, and print out minLeft, bottomSpaceLeft, and _leftAxis.axisMinimum
after

_leftAxis.axisMinimum = !isnan(_leftAxis.customAxisMin)
            ? _leftAxis.customAxisMin
            : (minLeft - bottomSpaceLeft)

I think _leftAxis.axisMinimum < 0 is the reason why you see the gap. I will try insert 0 in my demo.

@liuxuan30
Copy link
Member

I insert 0 in ChartsDemo bar chart, no gap if I call leftAxis.startAtZeroEnabled = YES; or the other one
0

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

I'm confused!
Are you saying you made your first entry a 0 and called leftAxis.startAtZeroEnabled = YES??

Just a side note: None of my data points are less than 0.0

@acegreen acegreen changed the title 2 Issues on latest version Gap issues on latest version Mar 7, 2016
@liuxuan30
Copy link
Member

I see you have 3 zero values, while I don't, so I manually insert zero values to see if there is bug. In my first test, I only have values >= 1
leftAxis.startAtZeroEnabled = YES or leftAxis.customAxisMin = 0.0; is to force the y axis starts from 0

Anyway, I need your help to print out minLeft, bottomSpaceLeft, and _leftAxis.axisMinimum, I think it should not happen if you called leftAxis.customAxisMin = 0.0
It's at BarLineChartViewBase.swift line 338

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

The zeros are random, but the case is not isolated to the above. In all my attempts, the gap is there. Also none of my entries are less than 0.0

Another example:
simulator screen shot mar 6 2016 9 54 49 pm

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

Side note #2: If I leave all my entries at 0, the labels are shifted to the middle of the chart.

simulator screen shot mar 6 2016 9 21 09 pm

@liuxuan30
Copy link
Member

@acegreen yeah, I just want to simulate your data sets in ChartsDemo. that's why I said
I need your help to print out minLeft, bottomSpaceLeft, and _leftAxis.axisMinimum, I think it should not happen if you called leftAxis.customAxisMin = 0.0
It's at BarLineChartViewBase.swift line 338

@liuxuan30
Copy link
Member

I also tried your all zero values in ChartsDemo, still no gaps. please try print out minLeft, bottomSpaceLeft, and _leftAxis.axisMinimum at BarLineChartViewBase.swift line 338 if possible;
all0
If you are using ios-charts embedded framework, well.. Could you try ChartsDemo and reproduce it? Or if we can have a live chat?

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

Result:
2016-03-06 22:00:18.032 StockSwipe[44628:1603879] minLeft 0, bottomSpaceLeft 0, and _leftAxis.axisMinimum 0

Case:
simulator screen shot mar 6 2016 9 54 49 pm

@liuxuan30
Copy link
Member

can we have a live chat? you only use left axis? your _leftAxis.axisMinimum seems fine...
seems the matrix is not correct? I am confused

@liuxuan30
Copy link
Member

@liuxuan30
Copy link
Member

So during the chat, it turned out that @acegreen is setting data first, after that is setting the chart without calling notifyDataSetChanged(). reversing the order and problem solved.

Le't get back to the table @danielgindi
Shall we force axisMinimum to 0 if customAxisMin is NaN? Or we let user to explicitly call customAxisMin = 0?

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

@liuxuan30 Appreciate the effort on this one.

I would force axisMinimum to 0. its an unnecessary step and most users will want to start at 0. Those that are looking for negative will need to implement that customAxisMin

@acegreen acegreen closed this as completed Mar 7, 2016
@liuxuan30 liuxuan30 reopened this Mar 7, 2016
@liuxuan30
Copy link
Member

@acegreen we still need to discuss the default behavior with @danielgindi , I will manage this issue, thanks

@acegreen
Copy link
Author

acegreen commented Mar 7, 2016

@liuxuan30 sure. I have my 2 cents above. Unsubscribing to let you guys discuss

@danielgindi
Copy link
Collaborator

Actually, axisMinimum is the property that is automatically calculated, and should not be used for that.
In order to constrain the axis range instead of the values calculated from the dataset - there's customAxisMin/customAxisMax.
Which is what you are doing, and it seems that the notify...() is the only thing you were missing :-)

@st-small
Copy link

@acegreen Can you help me with my values? How did you make your values without .00 (for example 23.00 now showing as 23)??? Thank you very much!

@liuxuan30
Copy link
Member

@st-small check out valueFormatter for any format issues.

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

4 participants