我有一个返回游标的数据库查询。我想使用http://www.android-graphview.org从该查询中绘制图形。
文档说这是用于创建图形的代码:
GraphView graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3)
});
graph.addSeries(series);
但是我想从游标中绘制图形,但是在 series [x] = new DataPoint 上出现错误“期望的数组类型”。
我的代码:
q = "SELECT _id, workout_diary_entry_set_a_weight, workout_diary_entry_set_a_reps FROM workout_diary_entries";
Cursor cursorEntries = db.rawQuery(q);
int countEntries = cursorEntries.getCount();
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[countEntries]);
for(int x =0;x<countEntries;x++){
Double workoutDiaryEntrySetAWeight = cursorEntries.getDouble(1);
Double workoutDiaryEntrySetAReps = cursorEntries.getDouble(2);
series[x] = new DataPoint(workoutDiaryEntrySetAWeight, workoutDiaryEntrySetAReps);
cursorEntries.moveToNext();
} // next
graphViewGraph.addSeries(series);