ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.54k stars 5.99k forks source link

Chart line is jagged with dense, nearly-flat data #2478

Open joejune opened 7 years ago

joejune commented 7 years ago

I'm using this library to chart dense, nearly-flat data. The y-value of the data is not exactly the same every time, but is very close. When the data gets very dense, strange jagged spikes appear on the graph. What's stranger is that these spikes go away when I increase the height of the graph.

I've pushed a branch which changes the ChartDemo to demonstrate this bug: https://github.com/junelife/Charts/commit/e56cd589209986758218b095483884d8f7d11e7f

Here are screenshots. The first shows the bug, the second has identical data and configuration, but the chartView is twice as tall and the bug doesn't manifest.

jagged clean

liuxuan30 commented 7 years ago

What's the y axis range then? Have you print out the y values for pixels and data values?

joejune commented 7 years ago

The y axis range has been hard-coded:

chartView.leftAxis.axisMinimum = 0
chartView.leftAxis.axisMaximum = 300000

The data set is very large, and can be seen in full here (you'll have to download the .json file): https://github.com/junelife/Charts/commit/e56cd589209986758218b095483884d8f7d11e7f#diff-55e35911eb3d651f6cc40d2fdc29516f. The important part is that this dataset is shown accurately in the flat graph, and inaccurately in the jagged graph.

I encourage you to download and run my example. Play with the height of the chart view and see how the behavior changes. Play with the size of the data and see how the behavior changes.

liuxuan30 commented 7 years ago

I don't have time to play yet, but I suggest you print the values you see jag, try round them since you have a big range.