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)
Getting Primary Y-Axis to Match Secondary Y-Axis
abrou001
<p>Hello all,</p><p> </p><p>I am working with BIRT 3.7.2 and have a query that returns the following fields.</p><p> </p><p>Average Max Quantity, Average Max Weight, Max Quantity, Max Weight, and Date</p><p> </p><p>The user is able to select from either quantity or weight and I have a chart with two y-axis to display the average as a bar and the maximum as a line. The reason for this is to allow potential outlyers be identified by the user. I was looking for some help to script setting both y-axis values to the same values. For example if the secondary y-axis goes from 0 to 100 then I want that to reflect on the primary y-axis as well. This way I am not displaying two y-axis with labels. As I will not know what the values are ahead of time scripting is my only option. Below is some scripting that I have found that doesn't work, though I believe this is a similar attempt to what I am working towards. Any help would be most appreciative.</p><p> </p><p>Thanks,</p><p>Adam Brousseau</p><p> </p><p>importPackage( Packages.org.eclipse.birt.chart.model.data.impl );</p><p>var cht = reportContext.getDesignHandle().findElement("Chart1");
var chart = cht.getReportItem().getProperty("chart.instance");</p><p>xAxis = chart.getBaseAxes()[0];
yAxis1 = chart.getOrthogonalAxes( xAxis, true)[0];
yAxis2 = chart.getOrthogonalAxes( xAxis, true)[1];
yscale1 = yAxis1.getScale();
yscale2 = yAxis2.getScale();
yscale2_min = yscale2.getMin();
yscale2_max = yscale2.getMax();
yscale1.setMin(yscale2_min);
yscale1.setMax(yscale2_max);
yscale2 = yscale1;
yAxis2.setScale(yscale1);</p>
Find more posts tagged with
Comments
abrou001
<p>It took some research with some modifications to make it work, but I got what I needed to get. Below is the code.</p><p> </p><p>/**</p><p>* Called before generation of chart model to GeneratedChartState.</p><p>* </p><p>*
@param
chart</p><p>* Chart</p><p>*
@param
icsc</p><p>* IChartScriptContext</p><p>*/</p><p> </p><p><strong class='bbc'>function</strong></p><p> </p><p> </p><p>beforeGeneration(chart, icsc)</p><p>{</p><p>importPackage(Packages.java.util);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.attribute);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.data.impl);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.component.impl);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.type.impl);</p><p> </p><p> </p><p><strong class='bbc'>var</strong> chart = icsc.getChartInstance();</p><p> </p><p>xAxis = chart.getBaseAxes()[0];</p><p>yAxis1 = chart.getOrthogonalAxes(xAxis, </p><p><strong class='bbc'>true</strong>)[0];</p><p>yAxis2 = chart.getOrthogonalAxes(xAxis, </p><p><strong class='bbc'>true</strong>)[1];</p><p>yscale1 = yAxis1.getScale();</p><p>yscale2 = yAxis2.getScale();</p><p>yscale1.setMin(NumberDataElementImpl.create(0));</p><p>yscale2.setMin(NumberDataElementImpl.create(0));</p><p>yscale1.setMax(NumberDataElementImpl.create(max_Value));</p><p>yscale2.setMax(NumberDataElementImpl.create(max_Value));</p><p> </p><p> </p><p><strong class='bbc'>var</strong> ySerieDef1 = yAxis1.getSeriesDefinitions().get(0);</p><p> </p><p><strong class='bbc'>var</strong> ySerieDef2 = yAxis2.getSeriesDefinitions().get(0);</p><p> </p><p> </p><p>//Used to set legend titles</p><p><strong class='bbc'>if</strong> (icsc.externalContext.scriptable.getParameterValue("Quantity") == <strong class='bbc'>true</strong>)</p><p>{</p><p>ySerieDef1.getSeries().get(1).setSeriesIdentifier(</p><p>"Average Max Quanity");</p><p>ySerieDef2.getSeries().get(1).setSeriesIdentifier(</p><p>"Max Quantity");</p><p>}</p><p> </p><p><strong class='bbc'>else</strong> <strong class='bbc'>if</strong> (icsc.externalContext.scriptable.getParameterValue("Weight") == <strong class='bbc'>true</strong>)</p><p>{</p><p>ySerieDef1.getSeries().get(1).setSeriesIdentifier(</p><p>"Average Max Weight");</p><p>ySerieDef2.getSeries().get(1).setSeriesIdentifier(</p><p>"Max Weight");</p><p>}</p><p>}</p><p>/**</p><p>* Called after populating the series dataset.</p><p>* </p><p>*
@param
series</p><p>* Series</p><p>*
@param
dataSet</p><p>* DataSet</p><p>*
@param
icsc</p><p>* IChartScriptContext</p><p>*/</p><p> </p><p><strong class='bbc'>function</strong></p><p> </p><p> </p><p>//Used to find the max number to set both y-axis maximum to</p><p>afterDataSetFilled( series, dataSet, icsc )</p><p>{</p><p>importPackage(Packages.java.io);</p><p>importPackage(Packages.org.eclipse.birt.chart.model.type.impl);</p><p>importPackage(Packages.org.eclipse.birt.chart.util);</p><p>importPackage(Packages.java.util);</p><p>ps = PluginSettings.instance();</p><p> </p><p>dsp = ps.getDataSetProcessor(series.getClass());</p><p>max_Value = dsp.getMaximum(dataSet);</p><p>}</p>
mwilliams
<p>There's also this devShare:</p><p> </p><p><a data-ipb='nomediaparse' href='
http://www.birt-exchange.org/devshare/_/designing-birt-reports/769-making-the-scales-of-a-dualaxis-chart-the-same'>http://www.birt-exchange.org/devshare/_/designing-birt-reports/769-making-the-scales-of-a-dualaxis-chart-the-same</a></p>
;