2016-03-19 18 views
0

データをLineGraphSeriesにインポートしようとしていますが、問題が発生しています。 SQLiteデータベースに挿入されたデータでグラフィックを作成したいのですが(リアルタイムではありません)、以下のコードを書いています。 私は自分の最終年度のプロジェクトで自分自身でJavaを学んでいるので、アンドロイドの経験はほとんどなく、誰でも手伝ってもらえると感謝しています。データベースからデータポイントにデータをロードする

@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); 
} 

答えて

0

1. DataPoint配列のサイズを設定します。
2.整数パラメータを使用してデータポイントを作成します。
3.データポイントをDataPointアレイに追加します。
4.配列でLineGraphSeriesを初期化します。

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); 
     //Assuming graphgic is of integer type 
     DataPoint v = new DataPoint(z, graphgic); 
     values[i] = v; 
    } 

}

関連する問題