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)
chart script for changing the bar colour
XFabien
Hello,
I have a question about the script in the chart.
My chart has two series ( "Series 1" and "Series 2" ).
In the 'onRender' event of the chart, I added the script below to change the color of the bar :
function beforeDrawDataPoint( dph, fill, icsc ) {
var group;
group= dph.getSeriesValue();
if(group== "Group 1") fill.set(64, 128, 128)
else if(group== "Group 2") fill.set(177, 208, 193)
else if(group== "Group 3") fill.set(246, 177, 135)
else fill.set(148, 162, 168)
}
It does work, my problem is that it change the color for both the two series, but I want it to change only the "Series 1".
I think it is maybe un simple question. If any of you can tell me how to get the "Series 1" in this exemple that may help me very much.
Thanks in advance.
Yao
Find more posts tagged with
Comments
johnw
You need to check which series it is before modifying. beforeDrawDataPoint is an event, so it will be triggered for all data points, regardless of which series its executing.
Check some of the examples starting with the link below. Everything you would want to know about chart scripting.
http://birtworld.blogspot.com/2011/10/birt-chart-palette.html
XFabien
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="97750" data-time="1331745368" data-date="14 March 2012 - 10:16 AM"><p>
You need to check which series it is before modifying. beforeDrawDataPoint is an event, so it will be triggered for all data points, regardless of which series its executing.<br />
<br />
Check some of the examples starting with the link below. Everything you would want to know about chart scripting.<br />
<br />
<a class='bbc_url' href='
http://birtworld.blogspot.com/2011/10/birt-chart-palette.html'>http://birtworld.blogspot.com/2011/10/birt-chart-palette.html</a><br
/></p></blockquote>
<br />
I have tried a lot with the exemple you gave me, but I didn't make it out correctly.<br />
Is it possible for you to give un other exemple?<br />
<br />
I appreciate very much your help.
tkopets
Take a look at <a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1466-styling-report-and-script-to-change-default-chart-palette/'>this
example</a>.<br />
<br />
You should use beforeGeneration function in onRender event.<br />
<br />
Something like this should work for you:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeGeneration( chart, icsc )
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
var color = ColorDefinitionImpl.create(181,181,169); // Desired color
var xAxis = ""; // X axis
var yAxis = ""; // Y axis
var xSeriesDefs = ""; // Series Definitions (X axis)
var ySeriesDefs = ""; // Series Definitions (Y axis)
var seriesPal = ""; // Series palette
// get x, y axes and their series definitions
xAxis = chart.getBaseAxes()[0];
yAxis = xAxis.getAssociatedAxes().get(0);
xSeriesDefs = xAxis.getSeriesDefinitions();
ySeriesDefs = yAxis.getSeriesDefinitions();
// apply color only to first serie !
seriesPal = ySeriesDefs.get(0).getSeriesPalette();
// insert color to palette as a first item
seriesPal.getEntries().add(0, color.copyInstance());
// apply also to category palette
var paletteByCategory = xSeriesDefs.get(0).getSeriesPalette();
paletteByCategory.getEntries().add(0, color.copyInstance());
}
</pre>
XFabien
Thanks for the reply.
But with your example, I don't sucessfully make it works.
tkopets
I don't understand what you mean...
Take a look, is this the desired output?
XFabien
Sorry for letting you misunderstanding.
The result will be like the example below :