0

I'm trying to import data into the LineGraphSeries but i'm having problems doing it. I want to create a graphic (not with real time modifications) with the data inserted into the SQLite database, and i wrote the following code to do it. Since i'm learning java on my own for my final year project I've very little experience with android and would be gratefull if anyone can help.

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

1 Answers1

0

1.Set the size of DataPoint array.
2.Create a datapoint with integer parameters.
3.Add the datapoint to the DataPoint array.
4.Initialise LineGraphSeries with the array.

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

}

Sneha.G
  • 11
  • 3