0

我遇到了这个问题,我从 sqlite 数据库中获取日期值并尝试在 X 轴上针对其他一些值绘制它们。但即使在 SO 上尝试了不同的解决方案后,我也无法解决这个问题。我得到的不是我的值,而是随机日期(1970 年 1 月 30 日),并且到处都是相同的日期。

请帮我解决一下这个。

这是获取日期的代码:

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

        int i = 0;
        int count = reportCursor.getCount();

        Date[] reportList = new Date[count];

        if(reportCursor.moveToFirst())
        {
            do
            {
                reportList[i] = new  Date(reportCursor.getLong(0));
                i++;
            } while(reportCursor.moveToNext());
        }

        reportCursor.close();
        return reportList;

FOr graph plotting


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


                        dataset = new XYMultipleSeriesDataset();
                        dataset.addSeries(fPriceseries);
                        dataset.addSeries(fMileageSeries);
                        }

在此处输入图像描述

4

1 回答 1

1

尝试以这种方式将日期添加到系列中,可能对您有用

long value = Math.abs(date.getTime() - 3* TimeChart.DAY);
series.add(new Date(value+ 3* TimeChart.DAY), x[i]);
于 2013-08-14T11:58:27.897 回答