I want to draw a bar chart which contains five individual bars - I have used Achartengine. I am able to display all five bars in the same color but I want to differentiate one bar with a different color, but I cant display more than one color. Please show me how to display different colors. My code...
values.add(new double[] {21,56,33,10,20});
int[] colors = new int[] { Color.rgb(227, 121, 15) };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
setChartSettings(renderer, "", "", "", 0,5, 0,100, Color.WHITE, Color.WHITE);
renderer.setXLabels(8);
renderer.setYLabels(10);
renderer.setDisplayChartValues(true);
mChartView= ChartFactory.getBarChartView(context, buildBarDataset(titles, values), renderer,
Type.DEFAULT);
layout.addView(mChartView, 350, 500);
Can be achieved by extending the SimpleSeriesRenderer and BarChart classes. Here is my solution for RangeBarChart (all thanks to gilenodm, wish I had some reputation to upvote your answer):
You have to use different SimpleSeriesRenderer inside buildBarRenderer() call, and define as many serie as the desired number of colors, this way (replacing your first two lines of code):
The rest of code should be same as yours, but I haven't tested it. AFAIK you need different series, because every serie can only have one color.
It's been a while since I use achartengine, but I think each series has to have its own colour. As a workaround, you could make the bar that you want to differentiate a member of its own series, and set a different colour for that series. Perhaps someone else has a better way though.
I made a hack to achieve this effect.
Org.achartengine.SimpleSeriesRenderer
changed the class, I added anint[] colors
and aboolean multipleColorsEnabled
with its getters and setters. So, I changed,org.achartengine.BarChart
in class, the method drawSeries, where is set the color of each bar in a loop, as follows:In the class that loads the data used: