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)
Add different color to one bar series from script based on dataset value.
charmi
Hi all,
Below I had displayed the code that will change the color of bar chart .But i have 2 y-series and this code will change color of both series.Does anyone have idea how to change color of only 1 series?Thanks in advance.
function beforeDrawDataPoint(dph, fill, icsc)
{
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
val = dph.getOrthogonalValue();
if( fill.getClass().isAssignableFrom(ColorDefinitionImpl)){
if (val == "string" ){
var mycolor = ColorDefinitionImpl.YELLOW();
r = mycolor.getRed();
g = mycolor.getGreen();
b = mycolor.getBlue();
fill.set(r,g,b );
}
}
}
Find more posts tagged with
Comments
mwilliams
Did you ever get an answer to this question? For future reference, post in the designing birt reports forum for birt designer questions!
Let me know.
HarshVardhan
<p>Hi, i want different colors for differnt bar i.e based on value in my bar chart, i m sending those values dynamicall from java classes, below is my scripted code, can any one suggest how i can colorised the axis values . its urgent</p>
<p>
if(count <list.size()){<br>
<br>
row["xAxis"] = list.get(count).getxAxis();<br>
row["yAxis"] = list.get(count).getyAxis();<br>
count++;<br>
return true;<br>
}<br>
return false;</p>
Matthew L.
<p>You can change the colors in the charts beforeDrawDataPoint function.</p>
<p>Attached is an example that sets each column to a different color based on either its column label or column value. I've also included series color code for reference.</p>
<p>Below is the code used in the charts onRender method:</p>
<p> </p>
<p> </p>
<p><span style="color:#008000;">//Sets bar color</span><br><span style="color:#800080;">function </span>beforeDrawDataPoint(dph, fill, icsc) {<br>
name = dph.getBaseDisplayValue(); <span style="color:#008000;">//Get label</span><br>
val = dph.getOrthogonalValue(); <span style="color:#008000;">//Get value</span><br>
<br>
<span style="color:#800080;">if</span> (name.indexOf(<span style="color:#0000ff;">"Australia"</span>)>=0) <span style="color:#008000;">//If label contains Australia</span><br>
fill.set(255, 0, 0); <span style="color:#008000;">//Make red</span><br>
<span style="color:#800080;">else if</span> (name.indexOf(<span style="color:#0000ff;">"France"</span>)>=0) <span style="color:#008000;">//If label contains France</span><br>
fill.set(0, 255, 0); <span style="color:#008000;">//Make green</span><br>
<span style="color:#800080;">else if</span> (val >= 80000 && val <= 90000) <span style="color:#008000;">//If value is between 80000 and 90000</span><br>
fill.set(0, 0, 255); <span style="color:#008000;">//Make blue</span><br>
<span style="color:#800080;">else</span> <span style="color:#008000;">//else</span><br>
fill.set(122,186,242); <span style="color:#008000;">//Make default blue</span><br>
} <span style="color:#008000;">//end</span><br>
<br>
<br><span style="color:#008000;">//Sets Series Legned color</span><br><span style="color:#800080;">function </span>beforeDrawLegendItem( lerh, bounds, icsc ) { <br>
<span style="color:#800080;">var </span>label = lerh.getLabel().getCaption().getValue(); <span style="color:#008000;">//Get label</span><br>
<span style="color:#800080;">if</span>( label == <span style="color:#0000ff;">"Series 1"</span>) <span style="color:#008000;">//If label matches Series 1 </span> <br>
lerh.getFill().set(200, 200, 200); <span style="color:#008000;">//Make gray</span><br>
<span style="color:#800080;">else </span><span style="color:#008000;">//else</span><br>
lerh.getFill().set(122,186,242); <span style="color:#008000;">//Make default blue </span><br>
} <span style="color:#008000;">//end</span></p>
<p> </p>