我终于得到了它的绘图,但是渲染的线在整个图形中保持不变,并且还存在x轴lebaling的问题以表示每周的天数。
This is what i want to achieve..
我是如何实现的...... GraphActivity.OnCreate。
LineGraphSeries lineGraphSeries = new LineGraphSeries<>(getChartData());
lineGraphSeries.setDrawDataPoints(true);
db = new DBAdapter(context);
db.openDB();
graphView.getViewport().setMaxY(db.getTotalMiles()*1.5);
db.closeDB();
设置图表。
public Datapoint getChartData(){
db.openDB();
Cursor cursor_miles = db.getchartdata();
DataPoint[] dataPoints = new DataPoint[cursor_miles.getCount()];
for (int i = 0; i<cursor_miles.getCount(); i++) {
cursor_miles.moveToLast();
double miles__ = cursor_cash.getDouble(cursor_miles.getColumnIndex(Constants.KEY_MILES));
long _time =(new Date(cursor_miles.getLong(cursor_miles.getColumnIndex(Constants.DATE_))).getTime());
dataPoints[i] = new DataPoint(_time + (i * 60 * 60 * 24 * 1000), miles__);
}
db.closeDB();
return dataPoints;
}
答案 0 :(得分:0)
您的问题可能是您每次迭代都使用moveToLast
而不是遍历cursor_miles Cursor。
而不是: -
public Datapoint getChartData(){
db.openDB();
Cursor cursor_miles = db.getchartdata();
DataPoint[] dataPoints = new DataPoint[cursor_miles.getCount()];
for (int i = 0; i<cursor_miles.getCount(); i++) {
cursor_miles.moveToLast();
double miles__ = cursor_cash.getDouble(cursor_miles.getColumnIndex(Constants.KEY_MILES));
long _time =(new Date(cursor_miles.getLong(cursor_miles.getColumnIndex(Constants.DATE_))).getTime());
dataPoints[i] = new DataPoint(_time + (i * 60 * 60 * 24 * 1000), miles__);
}
db.closeDB();
return dataPoints;
}
您可以使用: -
public Datapoint getChartData(){
db.openDB();
Cursor cursor_miles = db.getchartdata();
DataPoint[] dataPoints = new DataPoint[cursor_miles.getCount()];
while(cursor_miles.moveToNext) {
double miles__ = cursor_cash.getDouble(cursor_miles.getColumnIndex(Constants.KEY_MILES));
long _time =(new Date(cursor_miles.getLong(cursor_miles.getColumnIndex(Constants.DATE_))).getTime());
dataPoints[cursor_miles.getPosition()] = new DataPoint(_time + (cursor_miles.getPosition() * 60 * 60 * 24 * 1000), miles__);
}
cursor_miles.close();
db.closeDB();
return dataPoints;
}