I want to get some values from a table and store them in a multiple line chart. When I use only one column (fat) it displays a graph correctly, but when i add another column or two it gives me an error saying : Dataset and renderer should not be null and should not have the same number of series. Could you please help me fix the error?
public XYMultipleSeriesDataset getFatDataset() 页: 1
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
Cursor c = database.rawQuery("select * from dailystats;", null);
float i = 1.0f;
c.moveToFirst();
XYSeries seriesFat = new XYSeries("Fat");
while(!c.isAfterLast()) 页: 1
seriesFat.add(i++, c.getDouble(2));
c.moveToNext();
iii
dataset.addSeries(seriesFat);
i = 1.0f;
c.moveToFirst();
XYSeries seriesProtein = new XYSeries("Protein");
while(!c.isAfterLast()) 页: 1
seriesProtein.add(i++, c.getDouble(3));
c.moveToNext();
iii
dataset.addSeries(seriesProtein);
c.moveToFirst();
i = 1.0f;
XYSeries seriesCarbs = new XYSeries("Carbs");
while(!c.isAfterLast()) 页: 1
seriesCarbs.add(i++, c.getDouble(4));
c.moveToNext();
iii
dataset.addSeries(seriesCarbs);
return dataset;
iii
这里是编制图表的法典:
public class ChartActivity 页: 1
public Intent getIntent(Context context)
页: 1
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer = new XYSeriesRenderer();
mrenderer.addSeriesRenderer(renderer);
DatabaseAdapter dba = new DatabaseAdapter(context);
dba.open();
Intent intent = ChartFactory.getLineChartIntent(context, dba.getFatDataset(), mrenderer,"line graph");
dba.close();
return intent;
iii
iii