How can i make the XAxis in achartEngine format correctly? I would like it to have only the date value spaced correctly in the X-Axis with date values but i can't seem to get it work correctly.
this is what i have tried:
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.setBackgroundColor(Color.BLACK);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setGridColor(Color.LTGRAY);
mRenderer.setXLabels(0);
// mRenderer.setMargins(new int[]{0, 20, 0, 0});
XYSeriesRenderer renderer = new XYSeriesRenderer();
//renderer.setDisplayChartValuesDistance(1);
renderer.setColor(Color.GREEN);
mRenderer.setXLabels(10);
if(date_value.length < 10){ //date_value is a large array of dates for the X-Axis
for(int i = 0; i < date_value.length; i++){
mRenderer.addXTextLabel(i+1, date_value[i]);
}
}
else if(date_value.length > 10){
int mod = date_value.length % 10;
int add_mod = mod;
int last = date_value.length;
mRenderer.addXTextLabel(0, date_value[0]);
for(int i=0; i < 10; i++){
mRenderer.addXTextLabel(i, date_value[mod]);
mod+=add_mod;
}
mRenderer.setXLabelsAngle(90);
//mRenderer.addXTextLabel(date_value.length, date_value[last]);
}
/*get the last elements in the array and parse as double to set the maximum range for X*/
Calendar ist = Calendar.getInstance();
Calendar last = Calendar.getInstance();
ist.setTime(formatter.stringToDateReport(date_value[0]));
last.setTime(formatter.stringToDateReport(date_value[date_value.length-1]));
mRenderer.setXAxisMin(ist.get(Calendar.DATE));
mRenderer.setXAxisMax(last.get(Calendar.DATE));
mRenderer.addSeriesRenderer(renderer);
chartView = ChartFactory.getLineChartView(context, dataset, mRenderer);
return chartView;
this is what i get:
as you can see, They are not spaced correctly, they are on the x-axis line and have unwanted values e.g 10, 15, 20.. How can i correct this? Thank you.