PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.64k stars 9.02k forks source link

Reduce points drawn on large datasets #2920

Open befinitiv opened 7 years ago

befinitiv commented 7 years ago

Thanks for this nice library!

I have one issue: When using the following code, the drawing of a line chart takes prohibitively long (>1s, tested on Wiko Fever 4G and Nexus 7 13):

   for(int i=0; i<20000; ++i) {
        dataset0.addEntry(new Entry(i,i%10));
        dataset1.addEntry(new Entry(i,i%10));
        dataset2.addEntry(new Entry(i, i%10));
    }

    mLineData = new LineData(dataset0, dataset1, dataset2);
    mLineChart.setData(mLineData);

It seems to me as if all of the points are actually drawn, thus slowing down the update. Reducing the points drawn (by zooming in) the update rate goes back to acceptable levels.

IMO the points that are drawn should be limited to a reasonable number of points, independent of the zoom level. So at fully zoomed out the 20000 points should be "thinned" out to something like 100 points which will then be displayed.

I think the place I am talking about is this one here: https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java#L388 In there we iterate over all points within the X-bounds and draw them.

thburghout commented 7 years ago

I can confirm this as well. Also, when I was still running v2.2.4 it performed significantly better with the same large dataset. I cannot find the significant difference causing this between the two versions of the file linked by @befinitiv .

edit: this was not the case....

thburghout commented 7 years ago

Right now I'm using the Largest-Triangle-Three-Buckets algorithm to slim my data set before handing it to the graph. I have not found a way to automatically load in a more detailed data set when zooming in.

My largest data set is 3 lines, each with 72000 measurements.

NomadicDeveloper22 commented 3 years ago

I personally would like to see a built in function for this

something like the Douglas Peucker algorithm would be great and is the common method for this sort of thing. However implementing this on your own is a huge pain and would make sense to just have at as an included option with the MPAndroidChart