gpt4 book ai didi

android - 将数组中的值添加到 XY 系列

转载 作者:行者123 更新时间:2023-11-30 04:33:52 25 4
gpt4 key购买 nike

我想将 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;
}

关于android - 将数组中的值添加到 XY 系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7227302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com