我有自己的方法使用rawQuery从sqlite数据中检索数据。但现在我不知道如何将它放在图表视图中(例如:所有日期和所有权重列)放在graphview中
以下是检索数据的代码
DBHelperNote connect = new DBHelperNote(AnalysisGraph.this);
SQLiteDatabase db = connect.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM weight;", null);
if (cursor.moveToNext()) {
d = cursor.getString(cursor.getColumnIndex("date"));
e = cursor.getString(cursor.getColumnIndex("weight"));
tv.setText(d);
tc.setText(d);
}
db.close();
这是我的graphview,我如何使用我拥有的检索数据方法并添加或组合数据以在我的graphview中实现?
GraphView line_graph = (GraphView) contentView.findViewById(R.id.graph);
LineGraphSeries<DataPoint> line_series =
new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
line_graph.addSeries(line_series);
line_series.setDrawDataPoints(true);
line_series.setDataPointsRadius(10);
line_series.setOnDataPointTapListener(new OnDataPointTapListener() {
@Override
public void onTap(Series series, DataPointInterface dataPoint) {
Toast.makeText(getActivity(), "Series: On Data Point clicked: " + dataPoint, Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
您只需为列列表创建一个数据模型,然后将数据存储到该数据模型中。所以你很容易找到一个差距。
package yourpakage name;
public class datamodel {
private String id, weight, time, date;
public datamodel(String id, String weight, String time, String date) {
this.id = id;
this.weight = weight;
this.time = time;
this.date = date;
}
public String getId() {
return this.id;
}
public String getweight() {
return this.weight;
}
public String getTime() {
return this.time;
}
public String getDate() {
return this.date;
}
public void setid(String id) {
this.id = id;
}
public void setweight(String weight) {
this.weight = weight;
}
public void setTime(String time) {
this.time = time;
}
public void setDate(String date) {
this.date = date;
}
这是您的示例的数据模型,而不是将数据存储到那样的数据模型中。您可以在主Arraylist<datamodel>
中为您的文件名(文件)创建一个数组列表文件。
DBHelperNote connect = new DBHelperNote(AnalysisGraph.this);
file = new Arraylist<>;
SQLiteDatabase db = connect.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM weight;", null);
if (cursor.moveToNext()) {
file.add(new datamodel(data.getString(data.getColumnIndex("id")), data.getString(data.getColumnIndex("weight")),
, data.getString(data.getColumnIndex("time")),
data.getString(data.getColumnIndex("date"))));
}
db.close();
现在您的数据已存储到datamodel中,然后您只需从中检索数据。并轻松显示到图形中,您无需制作arraylist。