Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How do I set chart color through JSApi
pooh
Hi,
Am I able to set the line-chart series color through JSApi?
Thanks.
Find more posts tagged with
Comments
CBR
Yes you can do that. There is a method to set the color of the line and another method to set the color of the legend item. Do you display legend?
pooh
Yes I do display legend.
Could you please explain more on how I can do there through JSApi? I cant seem to find the function
pooh
I am using Actuate 11 btw
CBR
You have to use chart event scripting.<br />
To use chart event scripting you have to select the chart in the report and switch to the script tab.<br />
<br />
I implemented coloring a pie chart using scripting some weeks ago.<br />
<br />
i stored the color per series in the reportContext using the series name as key value. In your case you might just use fill.set(255, 255, 0) the integers are R G B<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawDataPoint( dph, fill, icsc )
{
var reportContext = icsc.getExternalContext().getScriptable();
var paletteList = reportContext.getGlobalVariable("palette");
seriesValue = dph.getBaseDisplayValue();
seriesValue = seriesValue.toUpperCase();
colorName = paletteList.get(seriesValue);
if( colorName!=null ){
fill.set(colorName.getRed(), colorName.getGreen(), colorName.getBlue());
}
}
</pre>
<br />
and for legend item<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawLegendItem( lerh, bounds, icsc )
{
var reportContext = icsc.getExternalContext().getScriptable();
var paletteList = reportContext.getGlobalVariable("palette");
//Scriptable rpCtx = icsc.getExternalContext().getScriptable();
seriesValue = lerh.getLabel().getCaption().getValue();
seriesValue = seriesValue.toUpperCase();
colorName = paletteList.get(seriesValue);
var fill = lerh.getFill();
if( colorName!=null ){
fill.set(colorName.getRed(), colorName.getGreen(), colorName.getBlue());
}
}
</pre>
<br />
The code should work for pie chart. It might be the case to do some changes to make it work for line charts. Just let me know if it worked.
CBR
I only work with open source version of BIRT. So there might be some easier way in the commercial edition
pooh
hi cbrell,
thanks so much for help.
I am using the trial version actually, am new to it.
I dont see the beforeDrawLegendItem though. Any idea ?
CBR
which version is Actuate 11?
I used BIRT 2.6
pooh
where can I find my Birt version?