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 に答える