Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart: LineChart with cubic bezier displays wrong (spikes and loops)

I am trying to make a LineChart with a cubic plot. The result is like in the screenshot below: the cubic bezier displays wrong and has "spikes". Can someone help me make it appear correctly?

This is my config :

        LineDataSet lineDataSet = new LineDataSet(entries,nameLabel);
        lineDataSet.setColor(Constants.colors.get(i));
        lineDataSet.setDrawValues(false);
        lineDataSet.setDrawCircles(false);
        lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);

Thank you cubic line chart with spikes

like image 695
Malcom Avatar asked Dec 26 '16 09:12

Malcom


1 Answers

Issues like this can have a number of causes:

  1. Not using the latest version of MPAndroidChart. Make sure you are using the latest version which includes all of the bug fixes.
  2. Using a cubic intensity that is not appropriate for the DataSet. Try experimenting with different values for:

    lineDataSet.setCubicIntensity():
    
  3. Using an incorrect granularity for the xIndices of the DataSet. Cubics work well with even and small gaps between xIndex entries. Try pre-processing your DataSet so that there is an appropriate granularity. For example, if the input data has timestamps with millisecond granularity but you only want to graph points for events that occur every few minutes, avoid making entries with the xIndex set to a millisecond value. Try instead making the Entry of the DataSet using seconds or even minutes.

If both of these approaches fail, your DataSet may require a horizontal cubic which will resolve the issue:

lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
like image 54
David Rawson Avatar answered Sep 28 '22 05:09

David Rawson