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)
Setting Chart Series Palette to use a gradient
jmangan
Is there a way to set a start and end color for a chart (say a pie chart), and have BIRT count the number of slices at run time and calculate a gradient for the slices and apply the colors to the Series Palette?
Find more posts tagged with
Comments
JasonW
Yes this is possible. Individual bars/slices support gradients, but you want the entire pie chart to act like a gradient I assume. There are a couple of ways to do this but the easiest is to just use a little script like:
piecnt = 0;
startColor = null;
endColor = null;
importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
function afterDataSetFilled(series, dataSet, icsc)
{
importPackage( Packages.java.io );
importPackage( Packages.org.eclipse.birt.chart.model.type.impl );
if( series.getClass() == PieSeriesImpl ){
if( series.getSeriesIdentifier() == "mypie" ){
var list = dataSet.getValues();
piecnt = list.length;
}
}
startColor = ColorDefinitionImpl.RED();
endColor = ColorDefinitionImpl.ORANGE();
//startColor = ColorDefinitionImpl.GREY();
//endColor = ColorDefinitionImpl.BLACK();
}
function buildPalette( sliceNumber )
{
var sr = startColor.getRed();
var sg = startColor.getGreen();
var sb = startColor.getBlue();
var er = endColor.getRed();
var eg = endColor.getGreen();
var eb = endColor.getBlue();
var nr = ((er-sr)/piecnt)*sliceNumber + sr;
var ng = ((eg-sg)/piecnt)*sliceNumber + sg;
var nb = ((eb-sb)/piecnt)*sliceNumber + sb;
var nc = ColorDefinitionImpl.create( nr, ng, nb );
return nc;
}
function beforeGeneration( chart, icsc )
{
sd = chart.getSeriesDefinitions( ).get( 0 );
sd.getSeriesPalette( ).getEntries( ).clear( );
for ( i = 1; i <= piecnt; i++ )
{
sd.getSeriesPalette().getEntries().add( buildPalette(i) );
}
}
In this example I used red to orange. Sample report and picture attached