Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Global scaling for multiple Y-axes
chris_w
I plot a chart with multiple Y-axes and I have a problem to scale that with a common value.
For example, I have 2 Y-axes und I just want to render the first Y-axis, the plot of the second Y-axis doesn't scale in the first one correctly. If you set the same scale for both axes, it's shown correctly. But I just want to set a common scale...
Is there a solution for this problem?
Thx
Find more posts tagged with
Comments
mwilliams
You could probably loop through the axes in your script and set them there.
chris_w
Mhhhh, ok... I have to calculate the MAX value in my Java Code...
How do i get this value in my event java script context?
Is it possible to fire database queries within the java script events?
mwilliams
You can grab the max value in the afterDataSetFilled function in the chart script like in the attached report. Then, you should be able to set the scale based on this.
chris_w
Thank you sir, that sounds good. I will try that...
mwilliams
Ok. Let me know if you run into issues!
chris_w
Hi, it works to retrieve the max value of the dataset.<br />
In the next step I tried to set the max value to the axes using <em class='bbc'>beforeDrawAxisLabel</em> phase.<br />
I'm not sure where to set...<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
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.getClass() == BarSeriesImpl){
dsp = ps.getDataSetProcessor(series.getClass());
//dataset max
var mmax = dsp.getMaximum(dataSet);
var existingMax = icsc.getExternalContext().getScriptable().getGlobalVariable("MaxBarValue");
if(mmax != null && existingMax < mmax){
mmax = Math.round(mmax);
while(mmax % 10 != 0){
mmax++;
}
icsc.getExternalContext().getScriptable().setGlobalVariable("MaxBarValue", mmax);
}
} else {
}
/**
* Called before rendering each label on a given Axis.
*
*
@param
axis
* Axis
*
@param
label
* Label
*
@param
icsc
* IChartScriptContext
*/
function beforeDrawAxisLabel(axis, label, icsc){
importPackage( Packages.org.eclipse.birt.chart.model.component.impl );
importPackage( Packages.org.eclipse.birt.chart.model.data.impl );
var max = icsc.getExternalContext().getScriptable().getGlobalVariable("MaxBarValue");
axis.getScale().setMax(NumberDataElementImpl.create(max));
}
</pre>
chris_w
Code to scale all Y-Axis to one common scale value on a generic way using BIRT scripting:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>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);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
ps = PluginSettings.instance( );
if(series.getClass() == BarSeriesImpl){
dsp = ps.getDataSetProcessor(series.getClass());
//dataset max
var mmax = dsp.getMaximum(dataSet);
var existingMax = icsc.getExternalContext().getScriptable().getGlobalVariable("MaxSliceValue");
if(mmax != null && existingMax < mmax){
mmax = Math.round(mmax);
if(mmax < 120){
mmax = 120;
}
while(mmax % 20 != 0){
mmax++;
}
icsc.getExternalContext().getScriptable().setGlobalVariable("MaxSliceValue", mmax);
chart = icsc.getChartInstance();
var yAxisSize = chart.getBaseAxes().length;
while(yAxisSize != 0){
yAxisSize--;
xAxis = chart.getBaseAxes()[yAxisSize];
var xAxisSize = chart.getOrthogonalAxes(xAxis, true).length;
while(xAxisSize != 0){
xAxisSize--;
yAxis = chart.getOrthogonalAxes(xAxis, true)[xAxisSize];
yscale = yAxis.getScale();
yscale.setMin( NumberDataElementImpl.create(0));
yscale.setMax(NumberDataElementImpl.create(mmax));
yAxis.setScale(yscale);
}
}
}
}
}</pre>
mwilliams
Here's an example that does it with afterDataSetFilled and beforeGeneration.