嗨,这是我的代码,但不起作用(最新版本的库)
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());
}
`这条鳕鱼的输出:不正确
但是当我更改代码时:
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());
}
并且输出是正确的,那么我应该怎么做才能从图表中删除旧数据?正确,但我想删除旧数据
问题解决了。我应该添加这一行。
if(set.getEntryCount() == MAX_ENTRIES) {
set.removeFirst();
// change Indexes - move to beginning by 1
for (Entry entry : set.getValues() )
entry.setX(entry.getX() - 1);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句