MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

How to Dynamically remove data from realtime graph?

Open ranj27 opened this issue 11 years ago • 2 comments

I want to display only 50 data points at any given point of time on a real-time graph. How to achieve this?

I am passing in a circular queue, because I have a large data which is posted simultaneously. I have to read this data and plot it at real-time

private void add(int i, CircularArrayQueue frameRate) { LineData data = graphView.getData(); if (data != null) { LineDataSet set = data.getDataSetByIndex(0); if (set == null) { set = createSet("Frame Rate"); data.addDataSet(set); }

            data.addXValue(set.getEntryCount() + "");
            int queueSize = frameRate.size();
            long temp = (long) frameRate.remove();
            Float yval = new Float(temp);
            if (set.getEntryCount() > 50) {
                data.removeXValue(0);
                Entry e = set.getEntryForXIndex(0);
                Boolean returnValue = data.removeEntry(e, 0);
            }

           data.addEntry(new Entry(yval, set.getEntryCount()), 0);

          graphView.notifyDataSetChanged(); 

            // limit the number of visible entries
            graphView.setVisibleXRangeMaximum(40);
            // mChart.setVisibleYRange(30, AxisDependency.LEFT);

            // move to the latest entry
            graphView.moveViewToX(data.getXValCount() - 41);

            graphView.zoomOut();
        }
    }

}

ranj27 avatar Oct 02 '15 05:10 ranj27

you can use graphView.clear() or graphView.clearValues() to remove the graph data.

himanshu1706 avatar Oct 07 '15 14:10 himanshu1706

I have the same requirement, too.

for a scenario in Time Series records, I think the trouble should be how to sync realtime chart data and keep it refresh after the action like @ranj27's code to call data.removeXValue(0); however, there is only one occurrence at RealtimeLineChartActivity in a whole library package.

Jasper009-So avatar Dec 03 '15 09:12 Jasper009-So