MPAndroidChart - grid line and limit line keep flickering in the background

I am trying to plot a real time graph using the MPAndroidChart library. Although I can successfully plot the graph, the grid lines and limit line continue to flicker while the graph is being drawn.

LineData data = myGraph.getData();

if (data != null) {
    LineDataSet set = data.getDataSetByIndex(0);

    if (set == null) {
        set = createSet();
        data.addDataSet(set);
    }
    // add a new x-value first
    DecimalFormat df = new DecimalFormat("#.0");
    String xVal = df.format(theRunningTime);
    data.addXValue(xVal+"s");
    data.addEntry(new Entry( yValue, set.getEntryCount()), 0);

    // let the chart know it data has changed
    audioGraph.notifyDataSetChanged();
    audioGraph.invalidate();
}

      

And the following code introduces the limit line in the graph

YAxis yl = myGraph.getAxisLeft();
yl.setTextColor(Color.WHITE);
yl.setTextSize(8f);
yl.setAxisMinValue(0);
yl.setDrawGridLines(false);
yl.setDrawAxisLine(true);
yl.setValueFormatter(new MyValueFormatter());     
yl.setStartAtZero(true);
//Remove any previous limit lines
yl.removeAllLimitLines();

LimitLine ll = new LimitLine(getThresholdValue(), "Threshold Value");
ll.setLineColor(Color.MAGENTA);
ll.setLineWidth(1f);
ll.setTextColor(Color.RED);
ll.setTextSize(7f);

yl.addLimitLine(ll);

      

+3


source to share





All Articles