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

1

5

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

Angloamerican answered 26/12, 2016 at 9:52 Comment(0)
B
8

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);
Briny answered 26/12, 2016 at 20:53 Comment(6)
I tried with lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);Angloamerican
It is a little betterAngloamerican
@Malcolm what granularity of time are you using? It could be a case where you need to use minutes rather than seconds. Hard to tell without looking at your data thoughBriny
I get the timestamp from server,so I am using seconds, do you advise me to use minutes ?Angloamerican
@Malcolm if the chart is still not the quality you want then please try minutes or half-hoursBriny
I will try with minutes and half-hours. Thank you for your answer @David RawsonAngloamerican

© 2022 - 2024 — McMap. All rights reserved.