我使用 aChartEngine 库创建了条形图。谁能帮助我如何增加条形的宽度并将条形定位在 X 轴的中心?
这是我的 BarGraph 类:
public class BarGraph {
public Intent getIntent(Context context){
XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
double[] range = {0,5,0,5};
int[] y = {24,30,12};
CategorySeries series1 = new CategorySeries("Today");
CategorySeries series2 = new CategorySeries("Next day");
CategorySeries series3 = new CategorySeries("2 days later");
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
for (int i=0;i<3;i++){
switch(i){
case 0:
series1.add(y[0]);
dataset.addSeries(series1.toXYSeries());
break;
case 1:
series2.add(y[1]);
dataset.addSeries(series2.toXYSeries());
break;
case 2:
series3.add(y[2]);
dataset.addSeries(series3.toXYSeries());
break;
}
}
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.GREEN);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.BLUE);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.RED);
mrenderer.setAxisTitleTextSize(16);
mrenderer.setChartTitleTextSize(20);
mrenderer.setLabelsTextSize(15);
mrenderer.setLegendTextSize(15);
mrenderer.setBarSpacing(0);
mrenderer.setXLabels(1);
mrenderer.addXTextLabel(2.5, "Outstanding jobs");
mrenderer.setMargins(new int[] {20, 30, 15, 0});
mrenderer.setAxesColor(Color.WHITE);
mrenderer.setChartTitle("Work per day");
mrenderer.setXTitle("Days");
mrenderer.setInitialRange(range, 1);
mrenderer.setBarSpacing(1);
mrenderer.setXAxisMin(0);
mrenderer.setXAxisMax(5);
mrenderer.setYAxisMin(0);
mrenderer.setPanEnabled(false, false);
mrenderer.setZoomEnabled(false, false);
mrenderer.addSeriesRenderer(renderer1);
mrenderer.addSeriesRenderer(renderer2);
mrenderer.addSeriesRenderer(renderer3);
Intent intent = ChartFactory.getBarChartIntent(context, dataset, mrenderer, Type.DEFAULT);
return intent;
}}
这是我得到的条形图的屏幕截图,
我需要这样的条形图
我怎样才能做到这一点?请帮我。