2
我使用achartengine繪製條形圖,並且我想根據y軸的值爲每個條形圖添加不同的顏色,如果值> 100,顏色=紅色Achartengine,爲條形圖中的酒吧設置不同的顏色
所以我的圖表看起來有點像這樣。
那麼,是不是可以用achartengine實現這一目標?
問候。
編輯:這是我的代碼,到目前爲止,
public class GraphActivity extends Activity {
LinearLayout chart;
private View mChart;
private static final int SERIES_NR = 2;
int[] income = {102, 95, 97, 100, 92, 99, 88};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
chart = (LinearLayout) findViewById(R.id.chart);
XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
myChartSettings(renderer);
mChart = ChartFactory.getBarChartView(this, getTruitonBarDataset(), renderer, BarChart.Type.DEFAULT);
chart.addView(mChart);
}
private XYMultipleSeriesDataset getTruitonBarDataset() {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
final int nr = 4;
Random r = new Random();
int[] x = { 0,1,2,3,4,5,6};
CategorySeries series = new CategorySeries("INCOME");
for(int i=0;i<x.length;i++){
series.add(income[i]);
}
dataset.addSeries(series.toXYSeries());
return dataset;
}
public XYMultipleSeriesRenderer getTruitonBarRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(50);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(25);
renderer.setLegendTextSize(15);
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(Color.BLUE);
renderer.addSeriesRenderer(r);
return renderer;
}
private void myChartSettings(XYMultipleSeriesRenderer renderer) {
renderer.setXAxisMin(0.8);
renderer.setXAxisMax(7.1);
renderer.setYAxisMin(50);
renderer.setYAxisMax(220);
renderer.addXTextLabel(1, "Tue");
renderer.addXTextLabel(2, "Wed");
renderer.addXTextLabel(3, "Thu");
renderer.addXTextLabel(4, "Fri");
renderer.addXTextLabel(5, "Sat");
renderer.addXTextLabel(6, "Sun");
renderer.addXTextLabel(7, "Today");
renderer.setYLabelsAlign(Paint.Align.RIGHT);
renderer.setBarWidth((float)25);
renderer.setShowAxes(false);
renderer.setShowLegend(false);
renderer.setMargins(new int[] {0,50,0,20});
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.TRANSPARENT);
renderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
renderer.setShowGrid(true);
renderer.setShowGridY(false);
renderer.setGridColor(Color.GRAY);
renderer.setXLabels(0); // sets the number of integer labels to appear
}
}
這是怎麼看起來像現在..
你究竟在哪裏卡住了? –
不知道如何給價值不同的顏色 – HeisenBerg
@TimCastelijns我已經更新了我的問題,希望你現在得到它 – HeisenBerg