2011-08-29 89 views
1

我想将SQLite中的值添加到XY系列中以创建图表。以下是我迄今所做的:将阵列中的值添加到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系列?有什么建议么?

回答

1

不确定你在这里用什么库创建你的图表(图表?)。我使用一个很好的图形引擎。我用它来获取包含在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; 
    } 
+0

是的,我想打一个图,我想从我的数据库(源码)的值(X,Y)的包含我之前插入的许多x和y值,你知道该怎么做吗?谢谢 – Handy

+0

嗨,你看过我的回答吗?它从数据库中获取2个值,并将它们用于图表上的点。 –

+0

是的,我读过你的答案,但它不起作用,你介意给我的例子项目?谢谢 – Handy