我想使用'com.jjoe64:graphview:4.0.1'绘制折线图。 我可以在没有错误的情况下在另一个项目中使用相同的代码运行但是当我在我的项目中尝试时,我遇到了错误“getSlotFromBufferLocked:unknown buffer”。 请帮我。 感谢。
Istatistik.java
private static final Random RANDOM = new Random();
private LineGraphSeries<DataPoint> series;
private LineGraphSeries<DataPoint> series2;
private int lastX = 0;
private int lastX2 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_istatistik);
// we get graph view instance
GraphView graph = (GraphView) findViewById(R.id.graph );
// data
series = new LineGraphSeries<DataPoint>();
//series.setColor(Color.MAGENTA);
graph.addSeries(series);
series2 = new LineGraphSeries<DataPoint>();
series2.setColor(Color.GREEN);
graph.addSeries(series2);
// customize a little bit viewport
Viewport viewport = graph.getViewport();
viewport.setYAxisBoundsManual(true);
viewport.setMinY(0);
viewport.setMaxY(10);
viewport.setScrollable(true);
}
@Override
protected void onResume() {
super.onResume();
// we're going to simulate real time with thread that append data to the graph
new Thread(new Runnable() {
@Override
public void run() {
// we add 100 new entries
for (int i = 0; i < 100; i++) {
runOnUiThread(new Runnable() {
@Override
public void run() {
addEntry();
}
});
// sleep to slow down the add of entries
try {
Thread.sleep(600);
} catch (InterruptedException e) {
// manage error ...
}
}
}
}).start();
}
// add random data to graph
private void addEntry() {
// here, we choose to display max 10 points on the viewport and we scroll to end
series.appendData(new DataPoint(lastX++, RANDOM.nextDouble() * 10d), true, 10);
series2.appendData(new DataPoint(lastX2++, RANDOM.nextDouble() * 10d), true, 10);
}