Home Analytics DevShare
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

Sample of how a bar chart can display dynamic marker lines

Clement WongClement Wong EM mod
edited July 30, 2014 in DevShare
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.<br />
<br />
In the afterDataSetFilled event, the minimum, maximum and average values are saved into a global variable.<br />
<br />
In the beforeGeneration event, the line markers are drawn in.<br />
<br />
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&#91;0];
    for (i=0; i &lt; items; i++) {
        total = total + Number(list&#91;i]);
        if (list&#91;i] &lt; theMin) theMin = list&#91;i];
        if (list&#91;i] &gt; theMax) theMax = list&#91;i];
    }
 
    icsc.getExternalContext().getScriptable().setGlobalVariable("minimum",theMin);
    icsc.getExternalContext().getScriptable().setGlobalVariable("average",(total/items));
    icsc.getExternalContext().getScriptable().setGlobalVariable("maximum",theMax);
    }
}

Clement Wong
Principal Analytics Architect

OpenText Corporation
http://www.actuate.com | http://www.opentext.com

Sign In or Register to comment.