Bar chart showing same color for the multiple bars

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
krishnamutthoju
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
antibot: No, of course not.
Location: India, Hyderabad

Bar chart showing same color for the multiple bars

Post by krishnamutthoju » Mon Dec 24, 2012 12:54 pm

Hi All,
I was used following jars to develop jfreecharts in my application.
1) jcommon-1.0.17.jar
2) jfreechart-1.0.14.jar
But the only problem with the same bar color, when the multiple bars having the same values.
Example:
Bar1-10, Bar2-10 , Bar3-10
In the above case three bars having the value 10 .Then those 3 bars showing same color even though setting different color individually for the each bar. But working fine if the bar values differ.

Code: Select all

LayeredBarRenderer renderer = new LayeredBarRenderer();
	renderer.setSeriesPaint(0, new Color(16, 78, 139));
	renderer.setSeriesPaint(1, new Color(192, 192, 192));
	renderer.setSeriesPaint(2, new Color(108, 166, 205));
	renderer.setSeriesPaint(3, new Color(67, 205, 128));
Thanks in advance
Radhakrishna.

krishnamutthoju
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
antibot: No, of course not.
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Post by krishnamutthoju » Tue Jul 30, 2013 11:14 am

Hi All,
Please help me how to get rid of above issue.
Thanks in advance
Radhakrishna.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Bar chart showing same color for the multiple bars

Post by david.gilbert » Wed Jul 31, 2013 6:45 am

The issue (I'm guessing) is that the LayeredBarRenderer draws the bars from the first series as the widest bars, and the bars from the last series as the narrowest. But, by default, the plot is rendering the series in reverse order (from last to first), so the wide bars from the first series are completely obscuring the narrower bars from the other series drawn earlier. You can fix that by setting the row rendering order in the plot:

Code: Select all

CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setRenderer(new LayeredBarRenderer());
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

krishnamutthoju
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
antibot: No, of course not.
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Post by krishnamutthoju » Thu Jan 30, 2014 11:30 am

Hi David,
Thanks for your reply. Unfortunately it doesn't work even though after modifying the order for Rowrenderer.
Please can you give me any other solution for this issue.

NOTE: This issue has been seen without setting any specific colours for each bar.
Thanks in advance
Radhakrishna.

krishnamutthoju
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
antibot: No, of course not.
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Post by krishnamutthoju » Thu Feb 13, 2014 12:42 pm

Hi All,
I have tried by setting my own colours for each index of the renderer when the bar chart has the same values as follows
bar1 =10; bar2 = 10; bar3 = 10;

Code: Select all

for(int index =0 ;index < bars.length; index++){
     renderer.setSeriesPaint(index,mycolours[index]);
}
So from the above code each index of the renderer get it's own colours, But when comes to bar chart all the bars[bar1,bar2,bar3...] are having same[One] colour. Please reply me if anyone knows the solution.
Thanks in advance
Radhakrishna.

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Bar chart showing same color for the multiple bars

Post by remiohead » Thu Feb 13, 2014 4:13 pm

Can you provide a self contained example please? (See http://sscce.org/).

Locked