How to refresh graph dynamic?
Init Chart.
final LineData mLineData = mChart.getData(); final ILineDataSet[] xSet = {mLineData.getDataSetByIndex(0)}; final int xSetArrayItem = 0; if (xSet[xSetArrayItem] == null) { xSet[xSetArrayItem] = createSet("Ecg", getResources().getColor(android.R.color.holo_red_dark)); mLineData.addDataSet(xSet[xSetArrayItem]); }
After this I'm doing subscribe for real data and putting it into graph.
mLineData.addEntry(new Entry(xValue++, ecgModel.getBody().getData()[i]), 0); mLineData.notifyDataChanged(); // let the chart know it's data has changed mChart.notifyDataSetChanged(); // limit the number of visible entries mChart.setVisibleXRangeMaximum(200); // move to the latest entry mChart.moveViewToX(xValue);
And Problem is I don't want to scroll X Axis. I want to put for example 400 inputs clear graph and let chart draw new 400 inputs.
Something like this:
if (xValue == 400) {
xValue = 0;
mLineData.clearValues();
mChart.invalidate();
}
- But this clearing graph but then nothing is draw on chart.