English 中文(简体)
缩略语
原标题:AChartGraph with multiple lines

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

最佳回答

所报的错误十分清楚:Dataset和iers不应成为无效,而不应有相同的系列,即你重新使用不同的系列和系列代号。 注:

//...
dataset.addSeries(seriesFat);
//....
dataset.addSeries(seriesCarbs);
//....

但只有<>>one <>>oneXYSeriesRenderer(:

mrenderer.addSeriesRenderer(renderer);

在我看来,你的守则应当开始简单地在<条码>XYMultipleSeriesRenderer()上添加另一条内容。

XYSeriesRenderer renderer2 = new XYSeriesRenderer();
mrenderer.addSeriesRenderer(renderer2);
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签