Reputation: 11
I've been researching this and not finding much out there--probably because it's very simple. I'm trying to populate a bar chart in agraphengine from a cursor that I have. I have confirmed that the cursor pulls back 30 rows (expected), but I don't know where to go from there.
Here is my array that I'm populating:
public static List<double[]> getChartData(int iDays){
List<double[]> values = new ArrayList<double[]>();
//cursor returns expected 30 results
Cursor graphData = db.query(CS_Table, new String [] {"count(*)-1"}, null, null, "strftime('%Y-%m-%d', " + Time + ")", "strftime('%Y-%m-%d', " + CS_Drink_Time + ") BETWEEN strftime('%Y-%m-%d', date('now','-" + iDays + " day')) and strftime('%Y-%m-%d','now')", Time , null);
for(graphData.moveToFirst(); graphData.moveToNext(); graphData.isAfterLast()) {
values.add(new double[] {graphData.getInt(0)});
graphData.moveToNext();
}
graphData.close();
return values;
}
And here is what is calling the function--from achartengine:
public Intent execute(Context context) {
String[] titles = new String[] { "total" };
List<double[]> values = new ArrayList<double[]>(DBhelper.getChartData(30));
values.addAll(DBhelper.getChartData(30));
int[] colors = new int[] { Color.BLUE};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
setChartSettings(renderer, "Drinks in the past " + DBhelper.getChartData(30) + " days", "Date", DBhelper.CS_YDrinks, 0,
/*y axis*/32, 0, /*x axis*/10, Color.GRAY, Color.LTGRAY);
renderer.setXLabels(12);
renderer.setYLabels(10);
renderer.setDisplayChartValues(true);
renderer.setXLabelsAlign(Align.LEFT);
renderer.setYLabelsAlign(Align.LEFT);
// renderer.setPanEnabled(false);
// renderer.setZoomEnabled(false);
renderer.setZoomRate(1.1f);
renderer.setBarSpacing(0.5);
return ChartFactory.getBarChartIntent(context, buildBarDataset(titles, values), renderer,
Type.STACKED);
The symptom is that it seems to only pull the first number from the array list as it will only plot one bar. Any suggestions are appreciated.
Upvotes: 1
Views: 1403
Reputation: 21
You need to put a corresponding value to match each bar in your string and color arrays. You are probably seeing only one blue bar with the title "total".
Upvotes: 2