Jump to content

BIRT Developer Center
Download


DevShare Source for user-contributed BIRT articles, tips and code

Devshare Home >> Setting Marker Line based on Date Parameter
- - - - -

Setting Marker Line based on Date Parameter

Download Resource

Summary:

Example dynamic marker line

Full Description:

Charts with date time axis use com.ibm.icu.util.Calendar. Date time parameters use java.util.Date. This example shows a report that has a date time parameter which is compared to the values of a date axis and used to add a marker line.
function afterDataSetFilled( series, dataSet, icsc )
{
  importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
  importPackage(Packages.com.ibm.icu.util);
  //x-axis Series
	 if (series.eClass().getName().equals("Series"))
	 {
     var list = dataSet.getValues();
   
     for ( i=0; i     {
      var cdt = icsc.getExternalContext().getScriptable().getParameterValue("myDtParm");
      
      var yr = list[i].fieldDifference( cdt, Calendar.YEAR );
      var mn = list[i].fieldDifference( cdt, Calendar.MONTH );
      var dy = list[i].fieldDifference( cdt, Calendar.DATE );
      if( yr == 0 && mn == 0 && dy == 0){
       intcountformaker = i;
      }
     }
    }
}
The afterDateSetFilled event is fired for every runtime series. This includes the category axis.
So this line:
series.eClass().getName().equals("Series")
will be true for the category series. Use "BarSeries", "LineSeries" etc for others or use getSeriesIdentifier()
This line:
icsc.getExternalContext().getScriptable().getParameterValue("myDtParm");
Gets the report parameter which is compared to each of the x-axis values using a the fieldDifference method of the Calendar class. When a match is found the intcountformaker global variable is set.
We then just dynamically create the marker in the beforeGeneration event which is called after the afterDataSetFilled event.
function beforeGeneration( chart, icsc )
{
 importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
 importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
 importPackage(Packages.org.eclipse.birt.chart.model.attribute);
 importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
 var xAxis =chart.getAxes().get(0);
 target_ml = MarkerLineImpl.create(xAxis, NumberDataElementImpl.create(intcountformaker));
 target_ml.getLabel().getCaption().setValue("Target");
 target_ml.getLineAttributes().getColor().set(32,145,245);
}


0 Comments