我想根据图像制作条形图,但我不知道如何在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
答案 0 :(得分:1)
我认为以下黑客攻击对您有用:
答案 1 :(得分:0)
这可能会解决您的问题:
renderer.getSeriesRendererAt(0).setGradientEnabled(真);
renderer.getSeriesRendererAt(0).setGradientStart(0, Color.rgb(025,117,025));
renderer.getSeriesRendererAt(0).setGradientStop(yMaxVal / 2, Color.rgb(94,158,94));
使用setGradientStart并停止在栏中的某个点之后定义颜色。