zemirco / swift-linechart

Line Chart library for iOS written in Swift
602 stars 68 forks source link

Y Axis [ Min / Max ] #12

Open ghost opened 9 years ago

ghost commented 9 years ago

func getMinimumValue() -> CGFloat { var minimum = Int.max for data in dataStore { var newMin = data.reduce(Int.max, { min(Int($0), Int($1)) }) if newMin < minimum { minimum = newMin } } return CGFloat(minimum) }

zemirco commented 9 years ago

Is there a way to get the data for the Y-Axis to start from a certain number in the dataset ?

What do you mean? You have an array [1, 2, 3, 4, 5, 6] and you only want to draw [4, 5, 6]? That is not possible.

Currently it's just starting from 0 making large numbers essentially a flat horizontal line at the top of the chart.

Did you try the latest version? It goes from the min up to the max value of your data.

https://github.com/zemirco/swift-linechart/blob/master/linechart/linechart/LineChart.swift#L112

I tried adjusting various draw parts of the code with a getMinimumValue func but it still didn't work.

That's now included. https://github.com/zemirco/swift-linechart/blob/master/linechart/linechart/LineChart.swift#L376

ghost commented 9 years ago

Thanks for the new version.

zemirco commented 9 years ago

You have to use latest beta version.

zoomies commented 9 years ago

I think I am seeing a related issue. When I create the chart and initially display it there are only a few Y values and they are small (including 0). As data comes in I populate the array and then I do a clear, and redisplay the chart. At some point the array that I am using only contains very large values, but the Y axis is not scaling, resulting in all the values looking like a flat line as in the attached screen capture.

image

eriktelepovsky commented 9 years ago

Same issue here. Any update with this? Btw. thank you very much for this library!

eriktelepovsky commented 9 years ago

I fixed that. Check my pull request please. Thank you.

ghost commented 7 years ago

Unable to set max and min for Y-Axis.

ghost commented 7 years ago

Is there any update for Y-Axis values?

ekscrypto commented 5 years ago

I submitted a PR which addresses this issue. Feel free to use my fork if desired.

binnn1234 commented 4 years ago

I submitted a PR which addresses this issue. Feel free to use my fork if desired.

Still, the number and label value for the y-axis are not set. Is there a way to solve it?

ekscrypto commented 4 years ago

I submitted a PR which addresses this issue. Feel free to use my fork if desired.

Still, the number and label value for the y-axis are not set. Is there a way to solve it?

The vertical axis labels are based on value ranges and will only show value if the range extends below/above the closest "label". You may try to set min/max values to you graph. If that still gives you trouble more information about your data set may be required, like what are the sample values, what are the parameters used for the chart, etc.