我使用以下代码在Android中使用AchartEngine绘制图表。即使我使用multiRenderer.setXAxisMin(0),最低值也设置为x轴的最小值。我还需要显示最低值。而且我还需要删除条形颜色指示器。
private String[] mMonth = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul" };
int[] x = { 0, 1, 2, 3, 4, 5, 6 };
int[] income = { 2000, 2400, 2500, 2700, 3000, 2800, 3500, 3700, };
XYSeries incomeSeries = new XYSeries("");
for (int i = 0; i < x.length; i++) {
incomeSeries.add(i, income[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(incomeSeries);
XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
incomeRenderer.setColor(Color.rgb(207, 44, 46));
incomeRenderer.setFillPoints(true);
incomeRenderer.setLineWidth(1);
incomeRenderer.setDisplayChartValues(true);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setBarSpacing(1);
for (int i = 0; i < x.length; i++) {
multiRenderer.addXTextLabel(i, mMonth[i]);
}
multiRenderer.addSeriesRenderer(incomeRenderer);
multiRenderer.setPanEnabled(false, false);
multiRenderer.setBackgroundColor(Color.rgb(255, 255, 255));
multiRenderer.setZoomEnabled(false, false);
multiRenderer.setXAxisMin(0);
multiRenderer.setLabelsTextSize(30);
multiRenderer.setShowAxes(false);
multiRenderer.setGridColor(Color.rgb(130, 130, 230));
multiRenderer.setInScroll(true);
multiRenderer.setMarginsColor(Color.argb(0x00, 0x01, 0x01, 0x01));
multiRenderer.setShowAxes(false);
multiRenderer.setXAxisMin(0);
int length = multiRenderer.getSeriesRendererCount();
for (int i = 0; i < length; i++) {
multiRenderer.getSeriesRendererAt(i).setDisplayChartValues(false);
}
LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
mChart = (GraphicalView) ChartFactory.getBarChartView(getBaseContext(),
dataset, multiRenderer, Type.DEFAULT);
chartContainer.addView(mChart);
答案 0 :(得分:0)
只需将x轴min设置为完全包含条宽的内容。例如:
renderer.setXAxisMin(-0.5);