Pooja Gaonkar
Pooja Gaonkar

Reputation: 1566

Dates on X-axis are not plotted achartengine line graph

I am stuck with this problem where I take date values from the sqlite database and try to plot them on X axis against some other values.But even after trying different solutions on SO I am unable to solve this. Instead of my values I get random dates (1/30/1970) and the same date everywhere.

Please help me with this.

heres the code for getting the dates:

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

Upvotes: 0

Views: 750

Answers (1)

Sreedhu Madhu
Sreedhu Madhu

Reputation: 2470

Try to add date to the series in this way, may it works for you

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

Upvotes: 1

Related Questions