Chart Series Colors
Below is the Birt reports javascript for forcing the color of a charts series and legend item based upon the values. Be sure that the series value match what comes out of the dataset
// ******* Forcing the color to the chart legend ************//
function beforeDrawLegendItem( lerh, bounds, icsc ){ // capture the value of the series var seriesLabel = lerh.getLabel().getCaption().getValue(); if(seriesLabel == "Series Value"){ lerh.getFill().set(0,128,255); // blue color }else if(seriesLabel == "Other Series Value"){ lerh.getFill().set(255,0,60); // red color } }
//********** Forcing the color of the chart series based upon its value *****//
function beforeDrawDataPoint( dph, fill, icsc ){ var seriesValue = dph.getSeriesDisplayValue(); // capture the value of the series if(seriesValue == "Series Value"){ fill.set(0,128,255); // blue color }else if(seriesValue == "Other Series Value"){ fill.set(255,0,60); // red color } } }If you want to have gradient colored series you can do the following:
function beforeDrawDataPoint( dph, fill, icsc ){ var seriesLabel = dph.getSeriesDisplayValue() // capture the value of the series importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl); // !!this is import to have!! if( fill.getClass().isAssignableFrom(GradientImpl)){ if (seriesLabel =="seriesvalue_1"){ fill.getStartColor().set(0,128,255); fill.getEndColor().set(226,251,250); } else if(seriesLabel == "seriesvalue_2") { fill.getStartColor().set(144,12,63); fill.getEndColor().set(253,188,213); }// and so on
In order to have your chart legend the same as your series when it is gradient you will need to do the following:
function beforeDrawLegendItem( lerh, bounds, icsc ){ importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl); var seriesName = lerh.getLabel().getCaption().getValue(); // capture the value of the series var fill = lerh.getFill(); if( fill.getClass().isAssignableFrom(GradientImpl)){ if(seriesName == "seriesvlaue_1"){ fill.getStartColor().set(0,128,255); fill.getEndColor().set(226,251,250); } else if(seriesName == "seriesvalue_2") fill.getStartColor().set(144,12,63); fill.getEndColor().set(253,188,213); //and so on
You cannot script a series for a gradient fill color and script the legend for a solid color. You have to have one or the other when scripting. Kept getting an error that didn't make sense until I applied the same setup for the legend as I did for the series datapoint.
Need to give credit to http://birtworld.blogspot.com/2011/10/birt-chart-palette.html after a lot of searching.
Comments
Post a Comment