Chart with a few series and a huge amount of data in each of them


#1

hi,

in my application, I have to show a few series of data. Each of series have to contain huge amount of points. 

I use trial version of chart library. I created 3 series and on runtime in each of them I add some count of DataPoints.

It looks like:

...

private DataAdapter<Integer, Integer> dataAdapter = new FireableDataAdapter<>();

...

@Override
protected void onCreate(Bundle savedInstanceState) {
    ....
    // If the chart doesn't have a line series then add one
    if (chart.getSeries().size() == 0) {
        LineSeries lineSeries = new LineSeries();
        chart.addSeries(lineSeries);
    }
    ....
    chart.getSeries().get(0).setDataAdapter(dataAdapter);
}

@Override
public void run() {
    dataAdapter.addAll(generateDataPoints()); // the same for 2 other series
    ....
    ((FireableDataAdapter<Integer, Integer>) dataAdapter).fire();
    ....
    new Handler().postDelayed(this, 10);
}

private List<DataPoint<Integer, Integer>> generateDataPoints() {
    final Random random = new Random();
    List<DataPoint<Integer, Integer>> result = new ArrayList<>();
    for (int i = 0; i < pointsCount; i++) {
        double next = last + (random.nextDouble() - 0.5 + bias) * 100;
        result.add(new DataPoint<Integer, Integer>(count++, (int) next));
        last = next;
    }
    return result;
}

At the beginning chart is fairly fast. but, the more points I add, the slower chart becomes. 

Amount of 150-170 thousands of points finally kills the chart and the app stops working.

Could you please advice what am I doing wrong, that chart is so slow? And is it possible to achieve fast chart on that amount of points?

p.s. in case of one series I receive the same behaviour, but amount of points is 400-450 thousands.

My device is Samsung Galaxy Tab 3.


#2

Hello Mobdevinc

Thanks for your interest in ShinobiControls!

As you have seen, things can start to slow down a little when the number of data points on a series becomes huge. There is no hard and fast rule to this figure - Android devices come in many shapes, sizes and performances specifications! We do tend to advise people that once you have more than 50,000 data points in your adapter, it may be worth considering taking steps to manage performance, when additional data points are added.

As can be seen in this blog post (https://www.shinobicontrols.com/blog/posts/2015/03/09/charts-in-listviews-part-3-streaming-data), this can be managed by taking an approach where as you add a new data point, you remove an old one.

You may also find this blog post useful:

We do acknowledge however that this may not necessarily suit everyone’s use case. If you need to have all of the data points added to your data adapter then you may like to consider sampling. Sampling in this sense means that you create your own custom adapter which would give a certain number of data points to the series at any one time. You would choose this number of data points yourself, dependant upon your specific use case. As the user pans along an axis, the adapter would need to serve up a fresh sample of data points to the series, relevant to the current displayed axis range.

I hope that this helps steer you in the right direction.

Thanks and kind regards,

Kai.