JohnD
JohnD

Reputation: 201

Create graph in achartengine from SQLite

I'm trying to build a graph in achartengine with data from my SQLite database. Getting the data from the database works, but it does always build just one point and not a graph. What am I doing wrong?

Here is my code:

public String getValue1(long l) {
String[] columns = new String[]{ KEY_Value1, KEY_Value2 };
Cursor c = Database.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null){
c.moveToFirst();
String value1 = c.getString(0);
return value1;
}
return null;
}

public String getValue2(long l) {
String[] columns = new String[]{ KEY_Value1, KEY_Value2 };
Cursor c = Database.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + l, null, null, null, null);
if (c != null){
c.moveToFirst();
String value2 = c.getString(1);
return value2;
}
return null;
}

DB getData = new DB(this);
getData.open();
for (int i = 1; value1 == null; i++) {
Stirng value1 = getData.getValue1(i);
String value2 = getData.getValue2(i);
}
getData.close();

x = Double.parseDouble(value1);
y = Double.parseDouble(value2);

mCurrentSeries.add(x, y);

if (mChartView != null) {
mChartView.repaint();
}
}

Upvotes: 0

Views: 1808

Answers (1)

Hesham Saeed
Hesham Saeed

Reputation: 5378

Edit the second part to this code:

DB getData = new DB(this);
getData.open();
for (int i = 1; value1 == null; i++) {
String value1 = getData.getValue1(i);
String value2 = getData.getValue2(i);

x = Double.parseDouble(value1);
y = Double.parseDouble(value2);

mCurrentSeries.add(x, y); //*** this has to be inside the loop in order to draw more than one point ***

}
getData.close();

if (mChartView != null) {
mChartView.repaint();
}
}

Upvotes: 1

Related Questions