How to show dates on x-axis in correct order

2019-08-26 21:34发布

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

enter image description here

The output i want is

enter image description here

1条回答
在下西门庆
2楼-- · 2019-08-26 22:20

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.

查看更多
登录 后发表回答