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

发布于 2024-12-02 00:42:48 字数 802 浏览 2 评论 0原文

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

I want to add a value from SQLite to an XY series to create a diagram. Here is what I've done so far:

 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();
 }

But I've got a problem at the line:

mCurrentSeries.add(x, y);

How I can add an Array to an XY series? Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没结果 2024-12-09 00:42:48

不确定您在这里使用什么库来创建图表(图表?)。我使用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;
    }

not sure what library you are using here to create your diagram (chart?). I use aChartEngine which is pretty good. The code I use to get a dataset containing a time series in aChartEngine is:

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文