Jump to content

BIRT Developer Center Download


Submitter

File Information

  • Submitted: Jul 30 2014 03:40 PM
  • Last Updated: Jul 30 2014 03:40 PM
  • File Size: 61.33KB
  • Views: 15879
  • Downloads: 144
  • Approved by: mwilliams
  • Approved on: 31 July 2014 - 07:56 AM
  • Summary: Sample of how a bar chart can display dynamic marker lines
  • Content Type: Designs & Code
  • BIRT Version: Actuate 11, Actuate 10, Actuate 9, 4.4, 4.3, 4.2, 3.7, 2.6

Download Bar chart with dynamic marker/threshold lines

* * * * * 2 Votes
bar chart dynamic marker marker threshold threshold line average minimum maximum



Screenshots
If there is a requirement on a bar chart to display dynamic marker lines (such as a minimum line, maximum line, or average line), then this script will create a minumum, average, and maximum marker/threshold line on the Y-Axis.

In the afterDataSetFilled event, the minimum, maximum and average values are saved into a global variable.

In the beforeGeneration event, the line markers are drawn in.

Works with OS BIRT charts and commercial BIRT HTML5 charts. The attached code was targeted for OS BIRT -- the chart output is in PNG format.
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 chart = icsc.getChartInstance();
var yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
var min_value = icsc.getExternalContext().getScriptable().getGlobalVariable("minimum");
var avg_value = icsc.getExternalContext().getScriptable().getGlobalVariable("average");
var max_value = icsc.getExternalContext().getScriptable().getGlobalVariable("maximum");

min_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(min_value));
min_ml.getLabel().getCaption().setValue("Min " + parseInt(min_value));             // parseInt
min_ml.getLabel().getCaption().getFont().setName("Arial");
min_ml.getLabel().getCaption().getFont().setSize(8);
min_ml.getLabel().getCaption().setColor( ColorDefinitionImpl.create(136,136,136));
min_ml.getLineAttributes().getColor().set(173,210,252);
min_ml.getLineAttributes().setThickness(1);

avg_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(avg_value));
avg_ml.getLabel().getCaption().setValue("Average " + parseFloat(avg_value).toFixed(2));
avg_ml.getLabel().getCaption().getFont().setName("Arial");
avg_ml.getLabel().getCaption().getFont().setSize(8);
avg_ml.getLabel().getCaption().setColor( ColorDefinitionImpl.create(136,136,136));
avg_ml.getLineAttributes().getColor().set(173,210,252);
avg_ml.getLineAttributes().setThickness(1);

max_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(max_value));
max_ml.getLabel().getCaption().setValue("Max " + parseInt(max_value));            // parseInt
max_ml.getLabel().getCaption().getFont().setName("Arial");
max_ml.getLabel().getCaption().getFont().setSize(8);
max_ml.getLabel().getCaption().setColor( ColorDefinitionImpl.create(136,136,136));
max_ml.getLineAttributes().getColor().set(173,210,252);
max_ml.getLineAttributes().setThickness(1);
}


function afterDataSetFilled( series, dataSet, icsc )
{
if( series.getSeriesIdentifier() == "Series 1"){
    var list = dataSet.getValues();
    
    var total=new Number();
    var theMin=new Number();
    var theMax=new Number();
    var items=list.length;
    
    theMin=list[0];
    for (i=0; i < items; i++) {
        total = total + Number(list[i]);
        if (list[i] < theMin) theMin = list[i];
        if (list[i] > theMax) theMax = list[i];
    }
 
    icsc.getExternalContext().getScriptable().setGlobalVariable("minimum",theMin);
    icsc.getExternalContext().getScriptable().setGlobalVariable("average",(total/items));
    icsc.getExternalContext().getScriptable().setGlobalVariable("maximum",theMax);
    }
}




Photo
Ganesamoorthi
May 04 2016 09:07 AM

Hi Everyone,

 

I am new to this birt reporting tool .I need your help .

 

My requirement is,the bar chart should display the number of request raised by each month . The main thing is if the request is not raised on march month means ,it should display null value .It should display all the records between  January to December month .

 

Thanks in advance.

Photo
telco-schilling
Dec 21 2016 01:50 PM

I was going crazy with this script for three days. For anyone trying to use this in the future you need to put the TITLE of you series in the line if( series.getSeriesIdentifier() == "Series 1"). For my chart I set the Title in Format Chart tab/ Series to something other than the default. 




0 user(s) are online (in the past 1 minutes)

0 members, 0 guests, 0 anonymous users