我正在尝试使用 achartengine 绘制一个图表,我需要从数据库中获取一组日期,以便我可以将它与 TimeSeries 一起使用。但是,我无法使用游标从数据库中检索日期。请帮助
heres my code:-
public Date[] getReportDates(ReportGraph reportGraph)
{
// TODO Auto-generated method stub
String [] columns = new String[]{KEY_ROW_ID, KEY_KM, KEY_FUEL_QTY, KEY_FUEL_PRICE, KEY_TOTAL_COST, KEY_MILEAGE, KEY_DATE,KEY_TANK_FULL};
String selectQuery = "SELECT _date FROM fuel_table";
reportCursor = ourDatabase.rawQuery(selectQuery, null);
Date[] reportList=null ;
int i = 0;
int count = reportCursor.getCount();
reportList = new Date[count];
if(reportCursor.moveToFirst())
{
do
{
reportList[i] = (Date)reportCursor.getLong(0); // ERROR here
i++;
}while(reportCursor.moveToNext());
}
reportCursor.close();
return reportList;
}
code for line chart:-
double[] fPrice;
double[] fMileage;
Date[] fDates;
XYMultipleSeriesRenderer rRenderer;
XYMultipleSeriesDataset dataset;
XYSeriesRenderer priceRenderer, mileageRenderer,dateRenderer;
public Intent getIntent(Context context)
{
FuelStoredInfo reportInfo =new FuelStoredInfo(context);
reportInfo.open();
fPrice=reportInfo.getReportData(this);
fMileage = reportInfo.getReportMileage(this);
fDates = reportInfo.getReportDates(this);
reportInfo.close();
TimeSeries fPriceseries = new TimeSeries("Fuel prices");
for(int i=0;i<fDates.length;i++)
{
fPriceseries.add(fDates[i], fPrice[i]);
}
TimeSeries fMileageSeries = new TimeSeries("Mileage");
for(int i=0;i<fDates.length;i++)
{
fMileageSeries.add(fDates[i],fMileage[i]);
}
// Our second data
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(fPriceseries);
dataset.addSeries(fMileageSeries);