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)
AreaChart - dynamically change series colors
yymer
I'm working on an AreaChart containing one series with grouping on 'label'.
Depending on what data is present in the db the grouping can give 2-6 groups.
I would now like to dynamically be able to change the color of these groups depending on what group they belong to,
for example:
All rows with 'label'-value "Error" is drawn in red.
Since "Error" is not always present, and not always the first value
using the SeriesPalette in the GUI is of no use here.
I've tried using the api:s to modify the palette dynamically with an onRender()-script checking the series title,
but I can't even mange to set the palette to one single color.
This is what my chart script looks like:
function beforeDrawSeries( series, isr, icsc )
{
var minSerie = icsc.getChartInstance().getSeriesForLegend();
minSerie[minSerie.length -1].getSeriesPalette().update(ColorDefinitionImpl.BLACK());
}
So...
What I would like to know is:
*How can I do this? (if doable)
*Is there are any guides/tutorials on the subject?
*What am I doing wrong with the tiny script posted?
I'm very thankful for all hints and help with this.
Warm greetings from northern Europe!
Find more posts tagged with
Comments
mwilliams
Hi yymer,
Are you using optional y-series grouping? Or actual separate series'? Also, what is your BIRT version? I'll try to do my testing in your version so I can attach any example I come up with.
yymer
Thanks for the quick reply!
I'm using the optional grouping, and running version 2.5.1.
I was first thinking of creating actual series with the api:s, but the optional grouping seamed
a bit easier so I went for that.
/ Ymer
mwilliams
Ymer,<br />
<br />
Try some code like this in your chart script:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
seriespalcnt = -1;
function beforeDrawSeries( series, isr, icsc )
{
if( series.getSeriesIdentifier() == "error" ){
importPackage( Packages.org.eclipse.birt.chart.model.attribute );
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
importPackage( Packages.org.eclipse.birt.chart.model.component.impl );
importPackage( Packages.org.eclipse.birt.chart.model.data.impl );
var chart = icsc.getChartInstance();
var newxAxis = chart.getBaseAxes()[0];
var newyAxis = chart.getOrthogonalAxes( newxAxis, true)[0];
var newseriesDef = newyAxis.getSeriesDefinitions().get(0);
newseriesDef.getSeriesPalette().getEntries().add(seriespalcnt, ColorDefinitionImpl.RED( ) );
}
seriespalcnt++;
}
</pre>
<br />
If you know all the different series', you could probably use similar script to color all groups consistently across your charts.
yymer
That definitely solves my problem!
Really great, I've been stuck with this for weeks.
mwilliams
Ymer,
No problem. Let us know whenever you have questions!