我想将SQLite的值添加到XY系列以创建图表。到目前为止,这是我所做的:

 Double a, b;
 mDbHelper = new NotesDbAdapter(this);
 mDbHelper.open();

 Cursor notesCursor = mDbHelper.fetchAllNotes();
 startManagingCursor(notesCursor);
 ArrayList x = new ArrayList();
 ArrayList y = new ArrayList();
 notesCursor.moveToFirst();

 for(int i = 0; i<notesCursor.getCount();i++){
     a = notesCursor.getDouble(notesCursor.getColumnIndex(mDbHelper.KEY_ROWID));
     b = notesCursor.getDouble(notesCursor.getColumnIndex(mDbHelper.KEY_RESULT));
 }
 x.add(a);
 y.add(b);

 notesCursor.moveToNext();

 mCurrentSeries.add(x, y);
 if (mChartView != null) {
      mChartView.repaint();
 }


但是我遇到了一个问题:


  mCurrentSeries.add(x, y);


如何将数组添加到XY系列?有什么建议么?

最佳答案

不知道您在这里使用哪个库来创建图表(图表?)。我使用一个非常好的aChartEngine。我用来获取包含aChartEngine中的时间序列的数据集的代码是:

public static XYMultipleSeriesDataset getDemoDataset(Cursor c,
            String title, String... columnName) {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

        TimeSeries series = new TimeSeries(title);


        try {
            if (c.moveToFirst()) {
                do {
                    int mins = c.getInt(c.getColumnIndex(columnName[0]));


                    java.util.Date date =null;
                    try{
                        date = DateFactory.stringToDate(c.getString(c.getColumnIndex(columnName[1])));
                    }catch(Exception e){

                    }
                    if(date==null){
                        continue;
                    }
                    series.add(date, mins);
                } while (c.moveToNext());
            } else {
                Log.d(TAG, "There were no values in the cursor.");
            }
        } finally {
            Log.d(TAG, "finally from getDemoDataset being called");
            c.close();
        }

        dataset.addSeries(series);

        return dataset;
    }

09-15 22:08