X轴上的日期未绘制achartengine线图

时间:2013-08-14 11:02:23

标签: android achartengine

我遇到了这个问题,我从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);
                        }

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试以这种方式向系列添加日期,可能适合您

long value = Math.abs(date.getTime() - 3* TimeChart.DAY);
series.add(new Date(value+ 3* TimeChart.DAY), x[i]);