How to Dynamically remove data from realtime graph?
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();
}
}
}
you can use graphView.clear() or graphView.clearValues() to remove the graph data.
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.