swift-linechart icon indicating copy to clipboard operation
swift-linechart copied to clipboard

Y Axis [ Min / Max ]

Open ghost opened this issue 10 years ago • 11 comments
trafficstars

  • Is there a way to get the data for the Y-Axis to start from a certain number in the dataset ?
  • Currently it's just starting from 0 making large numbers essentially a flat horizontal line at the top of the chart.
  • I tried adjusting various draw parts of the code with a getMinimumValue func but it still didn't work.

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) }

ghost avatar Mar 14 '15 22:03 ghost

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

zemirco avatar Mar 15 '15 09:03 zemirco

Thanks for the new version.

  • I gave it a try in XCode 6.2 and it had a few errors. I'll see if I can sort through it.
  • I was referring to say [ 780, 786, 800, 750 ] .. and the graph would start from 0 but I think you might have solved it.

ghost avatar Mar 15 '15 19:03 ghost

You have to use latest beta version.

zemirco avatar Mar 15 '15 19:03 zemirco

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

zoomies avatar Mar 30 '15 23:03 zoomies

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

eriktelepovsky avatar May 09 '15 06:05 eriktelepovsky

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

eriktelepovsky avatar May 09 '15 07:05 eriktelepovsky

Unable to set max and min for Y-Axis.

ghost avatar Jan 19 '17 09:01 ghost

Is there any update for Y-Axis values?

ghost avatar Jan 19 '17 09:01 ghost

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

ekscrypto avatar Feb 11 '19 04:02 ekscrypto

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?

binnn1234 avatar Feb 13 '20 02:02 binnn1234

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.

ekscrypto avatar Mar 06 '20 13:03 ekscrypto