问题
I have a line graph based on my database values where y axis has values and x axis has dates. As of now the chart is displayed date wise. But i want to display it different time periods like monthly and yearly.
Can anyone give me any ideas for this? Thank you
Here is my code:-
FuelStoredInfo reportInfo =new FuelStoredInfo(context);
reportInfo.open();
fPrice=reportInfo.getReportData(this);
fMileage = reportInfo.getReportMileage(this);
fDates =reportInfo.getReportDates(this);
reportInfo.close();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
TimeSeries fPriceseries = new TimeSeries("Fuel prices");
for (int i = 0; i < fDates.length; i++)
{
try
{
fPriceseries.add(sdf.parse(fDates[i].trim()), fPrice[i]);
}
catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
TimeSeries fMileageSeries = new TimeSeries("Mileage");
for(int i=0;i<fDates.length;i++)
{
try
{
fMileageSeries.add(sdf.parse(fDates[i].trim()), fMileage[i]);
}
catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(fPriceseries);
dataset.addSeries(fMileageSeries);
回答1:
From the AChartEngine point of view, you can tweak the displaying period of time by changing the visible area and repainting the graph:
renderer.setXAxisMin(minDate);
renderer.setXAxisMax(maxDate);
chartView.repaint();
来源:https://stackoverflow.com/questions/18299380/displaying-time-chart-in-achartengine-based-on-months-and-years