Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Problem with auto colors for grouped and stacked bar charts
dermoritz
i am creating grouped and stacked bar charts via birt-chart-api. The result looks as follows:<br />
<br />
Find more posts tagged with
Comments
kclark
dermoritz,<br />
<br />
You could do something like this in the onRender() of your chart<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawDataPoint( dph, fill, icsc )
{
var sValue = dph.getSeriesValue();
dph.get
if(sValue == "b1,m") {
fill.set(r, g,
;
} else if (sValue == "b1,w")
fill.set(r, g,
;
} // And so on for the stacked bars
}
function beforeDrawLegendItem(lerh, bounds, icsc)
{
label = lerh.getLabel();
labelString = label.getCaption().getValue();
if(labelString == "b1,m") {
lerh.getFill().set(r,g,B);
} else if (labelString == "b1,w")
lerh.getFill().set(r,g,B);
} // And so on for the rest of your legend
}
</pre>
<br />
If you have only a few groups you could try the above code. This will let you choose what colors for each series in your chart and change the legend to match.
dermoritz
thx,<br />
<br />
but in meantime i solved the problem.<br />
<br />
The problem was the bad javadoc. It is working if the used integers are negative! So if you want to shift color one position so that a "BarSeries" begins with the second color (red instead of blue) you have to call<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>groupSeries.getSeriesPalette().shift(-1);</pre>
<br />
So in my case i call<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>groupSeries.getSeriesPalette().shift(-lastBarSeriesSize);</pre>
<br />
(This was not the first time that i stumbled badly over the missing or bad documentation - i also got the 2 birt books but they didn't help neither :-P )
kclark
Thanks for the update on that, glad you got it working!