你好,這是我的代碼,但不能工作(的library最新版本)如何刪除MPAndroidChart中的舊數據?
LineData dataChart = mainChart.getData();
if (dataChart != null) {
LineDataSet set = (LineDataSet) dataChart.getDataSetByIndex(0);
if (set == null) {
set = (LineDataSet) createSet(ColorTemplate.rgb(colorChart), ColorTemplate.rgb(colorFill));
dataChart.addDataSet(set);
}
dataChart.addEntry(new Entry(set.getEntryCount(), sensorEvent.values[2]), 0);
dataChart.notifyDataChanged();
if(set.getEntryCount() == 20) {
set.removeFirst();
}
// let the chart know it's data has changed
mainChart.notifyDataSetChanged();
// limit the number of visible entries
mainChart.setVisibleXRangeMaximum(20);
mainChart.moveViewToX(dataChart.getEntryCount());
}
`這個鱈魚的產量: not correct
但是當我常我的代碼:
LineData dataChart = mainChart.getData();
if (dataChart != null) {
LineDataSet set = (LineDataSet) dataChart.getDataSetByIndex(0);
if (set == null) {
set = (LineDataSet) createSet(ColorTemplate.rgb(colorChart), ColorTemplate.rgb(colorFill));
dataChart.addDataSet(set);
}
dataChart.addEntry(new Entry(set.getEntryCount(), sensorEvent.values[2]), 0);
dataChart.notifyDataChanged();
// let the chart know it's data has changed
mainChart.notifyDataSetChanged();
// limit the number of visible entries
mainChart.setVisibleXRangeMaximum(300);
mainChart.moveViewToX(dataChart.getEntryCount());
}
和輸出是正確的,那麼我應該怎麼做才能從圖表中刪除舊數據? correct but I want delet old data
pieChart.invalidate();試試這個作爲第一行 – ashish
這是線圖不是piechart.I添加set.invalidate後removeFirst但不能再工作。請幫助我。 – Saeed