Bar chart showing same color for the multiple bars

A free public discussion forum for the JFreeChart class library.

Bar chart showing same color for the multiple bars

Postby 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
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Postby krishnamutthoju » Tue Jul 30, 2013 11:14 am

Hi All,
Please help me how to get rid of above issue.
Thanks in advance
Radhakrishna.
krishnamutthoju
 
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Postby 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: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11316
Joined: Fri Mar 14, 2003 10:29 am

Re: Bar chart showing same color for the multiple bars

Postby 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
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Postby 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.
krishnamutthoju
 
Posts: 7
Joined: Mon Sep 24, 2012 8:10 am
Location: India, Hyderabad

Re: Bar chart showing same color for the multiple bars

Postby remiohead » Thu Feb 13, 2014 4:13 pm

Can you provide a self contained example please? (See http://sscce.org/).
remiohead
 
Posts: 198
Joined: Fri Oct 02, 2009 3:53 pm


Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 3 guests