Marko Ćilimković
Marko Ćilimković

Reputation: 753

How to change color in primefaces bar chart for every column of the same series?

I have a problem with changing the color of the columns in my bar chart. I know how to change them if I have more series

<p:barChart id="outboxOfferChart" value="#{offerStatisticsBean.outboxOfferStatistics}" 
xaxisAngle="-70" datatipFormat="#{offerStatisticsBean.datatipFormat}" min="0" 
max="#{offerStatisticsBean.maxYAxis}" **seriesColors="FB5E09, CA04F1, 5EDD03, 04F655, 13FBC1, FC5560, FBFB18, B7FB09, 04C1FB, 034ED8, E704C1, FB0467, FC211D"** 
style="height:370px; width:380px;"/>

, but what if I have only 1 series, and want to change the color of every column to the same series? Help is much appreciated!

Upvotes: 2

Views: 5297

Answers (1)

steve
steve

Reputation: 625

Complete your primefaces chart with an extender attribute:

<h:outputScript>
function ext() {
  this.cfg.seriesDefaults.rendererOptions.varyBarColor = true;
}                               
</h:outputScript>       

<p:barChart ... extender="ext"/>

By default, a bar chart from a single series will have all the bar colors the same. But you can use different colors for each bar with varyBarColor property:

http://www.jqplot.com/deploy/dist/examples/multipleBarColors.html

Upvotes: 5

Related Questions