Sample of how a bar chart can display dynamic marker lines
Clement Wong
E mod
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.
<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[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); } }
Warning
No formatter is installed for the format ipb
0
Categories
- All Categories
- 107 Developer Announcements
- 53 Articles
- 104 General Questions
- 141 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 898 Cloud Fax and Notifications
- 76 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 118 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management