Home DevShare Designing BIRT Reports

Chart Script example of modifying series entries in the legend

by JasonW

Posted 2008-10-30 08:32:51.000

(0)  (0)   (11479 views)

Download (68.02 KB)

By downloading this item, you are agreeing to the Terms of Use for the site.

modify legend entries

Birt Version:-

This example uses a scripted dataset to get the names of each series for the legend.  A hidden table is placed on the report that calls the dataset.  The oncreate for the row sets persistent global variables with the names of the series.

 var st1 = this.getRowData().getColumnValue("series1");
var st2 = this.getRowData().getColumnValue("series2");
var st3 = this.getRowData().getColumnValue("series3");

reportContext.setPersistentGlobalVariable("seriestitle1", st1);
reportContext.setPersistentGlobalVariable("seriestitle2", st2);
reportContext.setPersistentGlobalVariable("seriestitle3", st3);

The chart series titles are set to

series1-title, series2-title, and series3-title in the third tab of the chart wizard.

Then in the chart script beforeDrawLegenItem the series titles are changed based on the value retrieved from the scripted dataset.

function beforeDrawLegendItem(lerh, bounds, icsc)
{

 if( lerh.getLabel().getCaption().getValue().compareToIgnoreCase("series1-title") == 0 ){
     var myst3 = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("seriestitle1");
  lerh.getLabel().getCaption().setValue(myst3);
 }
 if( lerh.getLabel().getCaption().getValue().compareToIgnoreCase("series2-title") == 0 ){
     var myst3 = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("seriestitle2");
  lerh.getLabel().getCaption().setValue(myst3);
 }
 if( lerh.getLabel().getCaption().getValue().compareToIgnoreCase("series3-title") == 0 ){
     var myst3 = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("seriestitle3");
  lerh.getLabel().getCaption().setValue(myst3);
 }

}

Download (68.02 KB)

By downloading this item, you are agreeing to the Terms of Use for the site.


 
Filter More