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)
Color BIRT Chart manipulation
sairag
My graph is binded to one dataset and I am using the following script in the on render, after data set filled to fix the axis details :
=============================================================================
importPackage( Packages.java.util );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
function afterDataSetFilled(series, dataSet, icsc)
{
if( series.getClass() == BarSeriesImpl ){
var list = dataSet.getValues();
var X= parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("X"));
var Y= parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("Y"));
var Z= parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("Z"));
var narray1 = new ArrayList( );
narray1.add(X);
narray1.add(Y);
narray1.add(Z);
dataSet.setValues(narray1);
}else{
var catArray = new ArrayList();
catArray.add("Naming Convention ");
catArray.add("Basic Profile ");
catArray.add("Non-Stanbdard ");
dataSet.setValues(catArray);
}
} ==============================================================================
If I want to use the different colors to each bar in the graph how can I improve the script.
Thanks
AR
Find more posts tagged with
Comments
sairag
I managed this without script by using "Edit Chart>Format chart> Series >Color By :Categories (I selected 'Categories' instead of 'Value Series').
Please let me know if I my approch is wrong.
kclark
You can also have each bar a different by optional y series grouping. If you have row["COUNTRY"] as your x series you can then use row["COUNTRY"] as the optional y series.<br />
<br />
You can also change the color of each bar with script based on the value using something likes this<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>function beforeDrawDataPoint( dph, fill, icsc )
{
var sValue = dph.getDisplayValue();
if (sValue.contains("SOMEDATA"))
{
fill.set(148, 198, 222);
}
}</pre>
sairag
Thanks Kclark !
I tried to use the suggested function , it worked fine.
Thanks
AR