Hiding a chart series based on dataset content
Options
One report I was designing needed to hide a series if it did not contain any data greater than 0. In the case of this report, the chart contained 3 series, and the third one needed this special ability to disappear if it was empty.<br />
To accomplish this, I added the following script to the chart:hasTarget = false;<br />
<br />
The function afterDataSetFilled checks for the maximum value of the third series. If it is greater than 0 (has data) a global variable hasTarget is set to true. Later on, the function beforeGeneration checks the value of hasTarget, and hides the third series if necessary.
To accomplish this, I added the following script to the chart:hasTarget = false;<br />
<br />
/** * Called before generation of chart model to GeneratedChartState. * * @param chart * Chart * @param icsc * IChartScriptContext */ function beforeGeneration( chart, icsc ) { yAxis = chart.getPrimaryOrthogonalAxis(chart.primaryBaseAxes[0]); if (hasTarget == false) { yAxis.seriesDefinitions[2].series[0].visible = false; } } /** * Called after populating the series dataset. * * @param series * Series * @param dataSet * DataSet * @param icsc * IChartScriptContext */ function afterDataSetFilled(series, dataSet, icsc) { importPackage(Packages.java.io); importPackage(Packages.org.eclipse.birt.chart.model.type.impl); importPackage(Packages.org.eclipse.birt.chart.util); importPackage(Packages.java.util); ps = PluginSettings.instance(); if (series.getSeriesIdentifier() == "Series 3") { dsp = ps.getDataSetProcessor(series.getClass()); if (dsp.getMaximum(dataSet) > 0) { hasTarget = true; } } }<br />
The function afterDataSetFilled checks for the maximum value of the third series. If it is greater than 0 (has data) a global variable hasTarget is set to true. Later on, the function beforeGeneration checks the value of hasTarget, and hides the third series if necessary.
0
Categories
- All Categories
- 109 Developer Announcements
- 49 Articles
- 100 General Questions
- 122 IM Services
- 40 OpenText Hackathon
- 31 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 897 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 121 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management