我想根据图像制作我的条形图,但我不知道如何在 y 轴的某个点之后更改条形颜色,我也想在 y 轴的特定点画一条线(图像中的红线),如图所示.请帮我怎么做?我的图表视图代码是
private void ChartView() {
String[] titles = new String[] { " " };
// int[] colors = new int[] { Color.BLUE, Color.BLUE };
multiRenderer = buildBarRenderer(colors);
multiRenderer.setApplyBackgroundColor(true);
multiRenderer.setMarginsColor(Color.WHITE);
multiRenderer.setBackgroundColor(Color.parseColor("#DCDCDC"));
setChartSettings(multiRenderer, "Calorie-Consume-Chart", chatX_lable,chatY_lable, -4,
6, 0, 240, Color.BLACK, Color.BLACK);
multiRenderer.getSeriesRendererAt(0).setDisplayChartValues(true);
//multiRenderer.getSeriesRendererAt(1).setDisplayChartValues(true);
multiRenderer.setXLabels(0);
multiRenderer.setYLabels(10);
multiRenderer.clearXTextLabels();
multiRenderer.setXLabelsAlign(Align.LEFT);
multiRenderer.setYLabelsAlign(Align.LEFT);
multiRenderer.setPanEnabled(false, false);
// renderer.setZoomEnabled(false);
multiRenderer.setZoomRate(1.1f);
multiRenderer.setBarSpacing(0.7);
multiRenderer.setZoomEnabled(true);
multiRenderer.
LinearLayout layout = (LinearLayout) findViewById(R.id.weightlinl);
layout.removeAllViews();
if (mChartView == null) {
mChartView = ChartFactory.getBarChartView(this,
buildBarDataset(titles, weekly_data_int)/* dataset */,
multiRenderer,org.achartengine.chart.BarChart.Type.DEFAULT);
layout.addView(mChartView);
} else {
// mChartView.repaint();
mChartView = ChartFactory.getBarChartView(this,
buildBarDataset(titles, weekly_data_int), multiRenderer,
org.achartengine.chart.BarChart.Type.DEFAULT);
mChartView.setBackgroundColor(Color.YELLOW);
layout.addView(mChartView);
// mChartView.repaint();
}
mChartView.invalidate();
}
protected void setChartSettings(XYMultipleSeriesRenderer renderer,
String title, String xTitle, String yTitle, double xMin,
double xMax, double yMin, double yMax, int axesColor,
int labelsColor) {
renderer.setChartTitle(title);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setXAxisMax(xMax);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setInitialRange(range);
renderer.clearXTextLabels();
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
}
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(12);
renderer.setChartTitleTextSize(16);
renderer.setLabelsTextSize(12);
renderer.setLegendTextSize(12);
int length = colors.length;
for (int i = 0; i < length; i++) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected XYMultipleSeriesDataset buildBarDataset(String[] titles, int j) {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++) {
CategorySeries series = new CategorySeries(titles[i]);
series.add(j);
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
![enter image description here][1]
[1]: http://i.stack.imgur.com/rKyjg.png