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)
Format Bar Chart Colours
Matt_t_t
Hello,
I am new to BIRT and all that and i have done what new people usually do and foolishly went straight to the advanced part. I have a chart that is a bar and line combination chart. Evrything works perfect but i want to be able to conditionally format one of the bars on the chart based on the value in either a parameter or report item i.e. text box etc.
My dataset is filtered based on two cascading parameters and the second one is the one i need to colour the bar.
My code works when i hardcode the value of one of the parameter options.
function beforeDrawDataPoint( dph, fill, icsc ){
temp = dph.getBaseValue();
if (temp == "Matthew"){
fill.set(29,158,254);
}
else{
fill.set(0,150,0);
}
}
I want to replace the "Matthew" with the value of the parameter in the Name paramter. The idea that whoever selects the name, their bar or column will be red and the others green etc. I have tried params["Name"] but no luck.
PLEASE HELP!!
Cheers
Matt
Find more posts tagged with
Comments
mwilliams
Hi Matt,
One thing you can do is to put the parameter in a persistentGlobalVariable in the report script and call that in the chart script for your check. Let me know if you have more questions.
Matt_t_t
Thanks for the speedy response. How do i do this?
Matt
mwilliams
Matt,
You can set the value in your report scripting with:
reportContext.setPersistentGlobalVariable("name", params["name"]);
Then, in your chart script, you can call this value with:
icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("name");
Matt_t_t
Still no luck, I have amended the code for the Chart script to this:
function beforeDrawDataPoint( dph, fill, icsc ){
temp = dph.getBaseValue();
if (temp == icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("Name")){
fill.set(29,158,254);
}
else{
fill.set(0,150,0);
}
}
And have added this to report script.
reportContext.setPersistentGlobalVariable("Name", params["Name"]);
Am i right in thinking i click the report layout and then go to the script tab and enter it into there.
Sorry for the thickness
mwilliams
Matt,
Try this check. It should work for you.
if(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("Name").equals(temp))
bhanley
Have a look at this working sample on the DevShare.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/devshare/designing-birt-reports/819-parameter-driven-bar-chart-formatting/#description'>Parameter-Driven
Bar Chart Formatting - Designs & Code - BIRT Exchange</a><br />
<br />
Good Luck!
Matt_t_t
I have sorted it. THanks to everyone for their help.
I used this
function beforeDrawDataPoint(dph, fill, icsc)
{
prac = icsc.getExternalContext().getScriptable().getParameterValue("Practice");
if (dph.getBaseDisplayValue().contains(prac)) {
fill.set(29,158,254);
}
else{
fill.set(0,150,0);
}
}