0
我試圖導入數據到LineGraphSeries,但我遇到問題。 我想創建一個插入到SQLite數據庫的數據的圖形(不是實時修改),我寫了下面的代碼來做到這一點。 由於我在我自己的最後一年項目中學習java,所以我對android很少有經驗,如果有人能幫忙,我會很樂於助人。將數據從數據庫加載到數據點[]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mediasdiab);
mediaglicemia = (TextView) findViewById(R.id.textmediaglicemia);
mediainsulina = (TextView) findViewById(R.id.textmediainsulina);
mediaporcoes = (TextView) findViewById(R.id.textmediaporcoes);
maxg = (TextView) findViewById(R.id.txtglicmax);
maxi = (TextView) findViewById(R.id.txtinsmax);
maxp = (TextView) findViewById(R.id.txtpormax);
ming = (TextView) findViewById(R.id.txtglicmin);
mini = (TextView) findViewById(R.id.txtinsmin);
minp = (TextView) findViewById(R.id.txtpormin);
try {
database = new Database(this);
conn = database.getWritableDatabase();
operacoes = new operacoes(conn);
}catch (SQLException ex)
{
Toast.makeText(getApplicationContext(), "Base de dados não acessivel. Erro:" + ex.getMessage(), Toast.LENGTH_LONG).show();
}
graph = (GraphView) findViewById(R.id.graficodiab);
listardados();
gerardatapoints();
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(values);
graph.addSeries(series);
}
//The error happens here
private void gerardatapoints(){
Cursor cursor = operacoes.todoaasfilas();
values = new DataPoint[idalto];
for (z=0; i<idalto; z++) {
cursor.moveToPosition(z);
diablinhagli = cursor.getString(cursor.getColumnIndex("GLICEMIA"));
graphgic = cursor.getInt(0);
values[z]= new DataPoint(z, graphgic);
}
seriesglicemia = new LineGraphSeries<DataPoint>(values);
}