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

Y Axis range calculation is incorrect for Bar Charts #2386

Closed
franqueli opened this issue Apr 24, 2017 · 3 comments
Closed

Y Axis range calculation is incorrect for Bar Charts #2386

franqueli opened this issue Apr 24, 2017 · 3 comments

Comments

@franqueli
Copy link
Contributor

When calculating the y axis range in the YAxis.swift calculate function if only one chart value is provided to the chart the range calculation is always 2.0.
This is because the dataMin and dataMax values passed to the method are the same.

It seems to me the range should always be calculated from the zero value.
If both dataMin and dataMax passed to the calculate method are positive, the range should be (dataMax - 0).
If both dataMin and dataMax passed to the calculate method are negative, the range should be 0 -dataMin.
if dataMin is negative and dataMax is positive, the range should be dataMax - dataMin.

Is the current behavoir expected?
barchartsmallrange

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 24, 2017

As you just have one value, it's expected.

It seems to me the range should always be calculated from the zero value.

If you want from 0, just set axisMinValue/MaxValue = 0

@franqueli
Copy link
Contributor Author

franqueli commented Apr 24, 2017

I don't think that works. The values I'm consuming come from a service. I don't know beforehand if the values are positive or negative. If I get a negative value from the service setting axisMinValue to 0 makes the chart not render correctly.

This will happen whenever the min and max chart values are close in range no matter how many values are being rendered in the chart.

@liuxuan30
Copy link
Member

You just want pure negative value or positive value to start from 0, and some other people don't want this. We can't make the decision so it's you to make. The library will use the max/min value to decide the range if you don't touch anything, so it usually works.

For your case, you can add a simple scan of your data to see if you want to start from 0 before displaying the chart.

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