我正在使用 achartengine 制作一个 LineGraph 类。问题是我无法从数据库中导入数据。我想将两个 int 数据库列添加到 int 系列中。我怎么做?这是我到目前为止所拥有的:
package com.weightmaster.awesome.development.chart;
import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.util.Log;
import com.weightmaster.awesome.development.WeightMasterOverviewActivity;
import com.weightmaster.awesome.development.database.WMSQLiteHelper;
public class LineGraph {
public static SQLiteDatabase dbSqlite;
public static WMSQLiteHelper helper;
public static XYMultipleSeriesDataset getDemoDataset(String title) {
Log.d(WeightMasterOverviewActivity.TAG, "Kjører metoden1");
Cursor cursor = helper.getDateAsc();
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
TimeSeries series = new TimeSeries("Line1");
TimeSeries series2 = new TimeSeries(title);
Log.d(WeightMasterOverviewActivity.TAG, "Kjører metoden");
cursor.moveToFirst();
Log.d(WeightMasterOverviewActivity.TAG,
"Cursoren flyttet til første element");
while (!cursor.isAfterLast()) {
int date = cursor.getInt((Integer) cursor.getColumnIndexOrThrow("date"));
Log.d(WeightMasterOverviewActivity.TAG, "Legger til dato");
int weight = cursor.getInt((Integer) cursor.getColumnIndexOrThrow("weight"));
Log.d(WeightMasterOverviewActivity.TAG, "Legger til vekt");
series2.add(weight, date);
cursor.moveToNext();
Log.d(WeightMasterOverviewActivity.TAG,
"Cursoren flyttet til neste element");
}
Log.d(WeightMasterOverviewActivity.TAG,
"There were no values in the cursor.");
cursor.close();
Log.d(WeightMasterOverviewActivity.TAG, "Den når til enden");
dataset.addSeries(series);
dataset.addSeries(series2);
return dataset;
}
public Intent getIntent(Context context) {
//Lager TimeSeries for den første linja
XYMultipleSeriesDataset dataset = getDemoDataset("Line1");
//Kode for render
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
//Optimalisering linje1
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.YELLOW);
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
// Optimalisering linje2 husk rekke følgen
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.BLUE);
renderer2.setPointStyle(PointStyle.SQUARE);
renderer2.setFillPoints(true);
//Legger til render seriene
mRenderer.addSeriesRenderer(renderer);
//Optimalisering grafen
mRenderer.setChartTitle("Test");
mRenderer.setZoomEnabled(true);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setBackgroundColor(Color.BLACK);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setXTitle("Dager");
mRenderer.setShowGrid(true);
mRenderer.addSeriesRenderer(renderer2);
Intent intent = ChartFactory.getLineChartIntent(context, dataset,
mRenderer, "Line Graph Title");
return intent;
}
}
它在调试器中的以下行停止:
Cursor cursor = helper.getDateAsc();