我创建了一个数据库,需要传递值来绘制图形。这是我遇到问题的地方。现在,图表仅显示但未绘制值。请帮忙!感谢
// MyDatabase
public class MyDatabase {
public static final String KEY_ROWID ="_id";
public static final String KEY_SYSTOLIC ="persons_systolic";
public static final String KEY_DIASTOLIC ="persons_diastolic";
public static final String KEY_PULSE ="persons_pulse";
private static final String DATABASE_NAME = "HealthDatabase";
private static final String DATABASE_TABLE = "personsTable";
private static final int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_SYSTOLIC + " TEXT NOT NULL, " +
KEY_DIASTOLIC + " TEXT NOT NULL, " +
KEY_PULSE + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public MyDatabase(Context c){
ourContext = c;
}
public MyDatabase open() throws SQLException{
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
}
public long createEntry(String sys, String dias, String pul) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_SYSTOLIC , sys);
cv.put(KEY_DIASTOLIC, dias);
cv.put(KEY_PULSE, pul);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[]{KEY_SYSTOLIC,KEY_DIASTOLIC,KEY_PULSE};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result =" ";
//int iRow = c.getColumnIndex(KEY_ROWID);
int iSys = c.getColumnIndex(KEY_SYSTOLIC);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iSys) + ",";
}
return result;
}
// MyActivity,这是我试图绘制图表的地方
MyDatabase myDb = new MyDatabase(this);
myDb.open();
String pull = myDb.getData();
pull = pull.substring(0, pull.length() - 1);
myDb.close();
double values = 3.0;
int i = 0;
//Here I don't know how to pass String pull in mSeries.
// also the data in pull is 140, 156, 132
mSeries.add(pull, values);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(Color.BLUE);
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
renderer.setDisplayChartValues(true);
mRenderer.addSeriesRenderer(renderer);
i++;
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
LinearLayout container = (LinearLayout)findViewById(R.id.Chart_layout);
container.addView(mChartView);