How to show dates on x-axis in correct order

亡梦爱人 提交于 2020-01-06 15:42:35

问题


Actually i have contructed an TimeChart graph in my app. But while showing dates on x axis it shows problem. The code i have used while designing chart using renderer is shown below along with the screen shot. If anyone knows why this problem arises please help me to solve this out.

Code:

    Calendar pCalendar_FirstDay = Calendar.getInstance();
    int nMinDay = pCalendar_FirstDay.getActualMinimum(Calendar.DATE);
    Date currentDate = pCalendar_FirstDay.getTime();        


    renderer = new XYMultipleSeriesRenderer();     

    //set value for x axis      
    renderer.setChartTitle("Weight / Temperature");
    renderer.setXLabels(15);        
    renderer.setXAxisMin(new Date(currentDate.getYear(), currentDate.getMonth(), nMinDay).getTime());
    renderer.setXAxisMax(currentDate.getTime());
    renderer.setXLabelsAlign(Align.CENTER);

    //set value for y axis
    renderer.setYLabels(10);  
    renderer.setYTitle("Weight", 0);
    renderer.setYAxisMin(10, 0);
    renderer.setYAxisMax(90, 0);
    renderer.setYAxisAlign(Align.LEFT, 0);
    renderer.setYLabelsAlign(Align.LEFT, 0);

    renderer.setPanLimits(new double[]{0,currentDate.getTime(), 10, 90});
    renderer.setAxisTitleTextSize(12);
    renderer.setChartTitleTextSize(12);
    renderer.setLabelsTextSize(10);
    renderer.setLegendTextSize(12);
    renderer.setPointSize(5f);  
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.parseColor("#F5F5F5"));
    renderer.setMarginsColor(Color.parseColor("#F5F5F5"));
    renderer.setAxesColor(Color.LTGRAY);
    renderer.setLabelsColor(Color.parseColor("#5f5f5f"));          
    renderer.setShowGrid(true);
    renderer.setGridColor(Color.GRAY); 

The output i got

The output i want is


回答1:


From your APIs, I presume you are using AChartEngine. How did you build the TimeChart instance? You should be doing something like this:

ChartFactory.getTimeChartIntent(context, dataset, renderer, pattern);

where pattern is a date formatting format which you should tweak for getting the desired display.



来源:https://stackoverflow.com/questions/9971855/how-to-show-dates-on-x-axis-in-correct-order

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