Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Disabling legend when series value is 0
bhavyasingh.k@gmail.com
<p>Hi,</p>
<p> </p>
<p>I am using BIRT 3.2.21 . I am new to it. I am facing an issue where i have to disable the legends when any one of the bar column value is 0. for example if i have two series and one of the series value is 0 then i have to disable the legend.</p>
<p>Please help.</p>
Find more posts tagged with
Comments
Matthew L.
<p>Assuming the chart is SVG, this can be accomplished using some code in the charts onRender method.</p>
<p>Below is the code I use in the attached example that demonstrates this.</p>
<p>See the attached example for more detail.</p>
<pre class="_prettyXprint _lang-js">
//Please note that all custom code received from Actuate Support is officially untested and unsupported.
//This is meant for guidance purposes only and should not be implemented in a production environment without proper testing.
seriesWithoutValuesArray=[]; //Set array variable
function afterDataSetFilled(series, dataSet, icsc){ //Happens before beforeGeneration
importPackage(Packages.org.eclipse.birt.chart.util);
ps = PluginSettings.instance();
dsp = ps.getDataSetProcessor(series.getClass());
if ( !parseFloat(dsp.getMaximum(dataSet)) > 0) //If dataSet value is not greater than 0
seriesWithoutValuesArray.push(series.getSeriesIdentifier()); //Push Series name to array
}
function beforeGeneration( chart, icsc ){ //Happens after afterDataSetFilled
yAxis = chart.getPrimaryOrthogonalAxis(chart.primaryBaseAxes[0]);
for (var i = 0; i < yAxis.seriesDefinitions.size(); i++) //Loop through series's
if (seriesWithoutValuesArray.indexOf(yAxis.seriesDefinitions[i].series[0].seriesIdentifier) > -1 ) //If series name is in the Series array from afterDataSetFilled
yAxis.seriesDefinitions[i].series[0].visible = false //Hide the series
}
</pre>
bhavyasingh.k@gmail.com
<p>Hi Thanks for the reply ,</p>
<p>I have only 2 series , if one of the series value is 0 , i have to disable both the legends.</p>
<p> </p>
<p>The above code is for hiding the series i guess?</p>
<p>but will this hide the legends?</p>
Matthew L.
<p>Here is an image of the before and after using the script.</p>
bhavyasingh.k@gmail.com
<p>I am not getting the expected output.</p>
<p>when i try displaying the value of </p>
<p>icsc.getExternalContext().getScriptable().getParameterValue("CategoryValue ")</p>
<p>it gives me null, where CategoryValue is the dataset value of first series</p>
<p> </p>
<p>Can you please tell me how we get the value of a particular dataset in chart?</p>
<p> </p>
<p>Can you please suggest me some reference books from which i could read about the scriptcode of BIRT?</p>
bhavyasingh.k@gmail.com
<p>Thanks Mathew for the reply. It is working..</p>