Displaying time chart in achartengine based on months and years

给你一囗甜甜゛ 提交于 2019-12-11 08:48:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!