1

我想将 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 系列?有什么建议么?

4

1 回答 1

1

不确定您在这里使用什么库来创建图表(图表?)。我使用非常好的 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;
    }
于 2011-08-29T08:45:39.557 回答