Android 在数据库中使用数据绘制图形
我想在android上绘制一个图形,使用android上已经创建的本地数据库中存储的数据,因此首先我尝试使用以下函数检索插入的数据Android 在数据库中使用数据绘制图形,android,database,Android,Database,我想在android上绘制一个图形,使用android上已经创建的本地数据库中存储的数据,因此首先我尝试使用以下函数检索插入的数据 public String getname(int i) { Cursor cursor = null; try { SQLiteDatabase db = this.getWritableDatabase(); cursor = db.rawQuery(SQL_CATEGORY_NAME , new String[]
public String getname(int i)
{
Cursor cursor = null;
try {
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.rawQuery(SQL_CATEGORY_NAME , new String[] { Integer.toString(i) } );
return (cursor.moveToFirst()) ? cursor.getString(0) : null;
} finally {
if (cursor != null) cursor.close();
}
}
然后,我使用以下代码将其值插入到图形中:
public class Graphe extends AppCompatActivity {
Helper h;
Contact c ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graphe);
GraphView graphView= findViewById(R.id.graphe);
LineGraphSeries<DataPoint>series = new LineGraphSeries<>();
for (int x=1 ; x<c.getId(); x++ )
{
series.appendData(new DataPoint(Double.parseDouble(h.getname(c.getId())),x),true,c.getId());
}
graphView.addSeries(series);
}
公共类图表扩展了AppCompative活动{
助手h;
联系c;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
GraphView GraphView=findViewById(R.id.graph);
LineGraphSeries=新的LineGraphSeries();
对于(int x=1;x函数中的字符串是从此行重新加载的:私有静态最终字符串SQL_CATEGORY_NAME=“SELECT”+“nom”+”from“+”contact“+”,其中“+”ID+“=?”;