|
Re: Chart with 2 y-axis series - problem sorting [message #1009876 is a reply to message #1009592] |
Fri, 15 February 2013 22:55 |
|
So, two different axes and one goes from 0 to 9 and the other from 9 to 0? Not just two series on an axis? To do this, you'd need to reverse the values in the series associated with the axis you want to reverse and then simply replace the y-axis label values to be in the reverse order. For example, if you had values 1, 3, and 7 on the reversed axis, you would actually need to make them 8, 6, and 2. These values would plot normally, but when you change the axis labels, they would appear as if they were the original values on a reversed axis. Hope this makes sense. Let me know if you need an example.
Michael
Developer Evangelist, Silanis
|
|
|
|
Re: Chart with 2 y-axis series - problem sorting [message #1010268 is a reply to message #1010242] |
Sun, 17 February 2013 02:08 |
David Good Messages: 41 Registered: September 2012 |
Member |
|
|
HI Mimmo,
The following is the code I used to reverse a secondary y-axis from 0-5 to 5-0 and their associated values. I created it using a single y-axis example provided by Jason Weathersby (http://birtworld.blogspot.com.au/2008/12/birt-reversing-chart-scale.html).
My code will need to be modified in your case (i.e. series name), but should help.
David
//Global scale, this is set for the secondary Y-axis.
//I am modifying it to list in reverse order (i.e. 5 at the bottom)
gblscale =5;
//*** this is the first event called for charting
//So set scale here
function beforeDataSetFilled( series, idsp, icsc )
{
// We can also link to a report param so users can adjust the scale at will
gblscale = 5; // icsc.getExternalContext().getScriptable().getParameterValue("Scale");
}
function afterDataSetFilled(series, dataSet, icsc)
{
// Change the data set values to new values.
// i.e. a 2 becomes a 3 so it plots higher on chart, but we set labels to display 2, tricking the chart.
// In chart builder, the series names of the series are the identifiers
if( series.getSeriesIdentifier() == "Capacity"){
var list = dataSet.getValues();
for ( i=0; i < list.length; i=i+1)
{
list[i] = gblscale - list[i];
}
}
}
function beforeGeneration(chart, icsc)
{
importPackage( Packages.org.eclipse.birt.chart.model.data.impl );
xAxis = chart.getBaseAxes()[0];
//Select the 2nd Y-axis from axis array
// for 1st Y-axis use: yAxis = chart.getOrthogonalAxes( xAxis, true)[0]
yAxis = chart.getOrthogonalAxes( xAxis, true)[1]
yscale = yAxis.getScale();
yscale.setStep (1); // Set the axis step interval here
// this sets default min/max - we over ride next function
yscale.setMin( NumberDataElementImpl.create(0) )
yscale.setMax( NumberDataElementImpl.create(gblscale) )
yAxis.setScale(yscale);
}
function beforeDrawAxisLabel(axis, label, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
if (axis.getType() == AxisType.LINEAR_LITERAL){
// this condition only for Y-axis' (LINEAR_LATERAL)
// only override the non-primary Y-axis
if (!axis.isPrimaryAxis()) {
var val = parseFloat(label.getCaption().getValue());
var newval = gblscale - val;
label.getCaption().setValue(newval);
}
}
}
function beforeDrawDataPointLabel(dph, label, icsc)
{
// get the series name
var currSeriesName = dph.getSeriesValue();
//only change data poiint labels for the 'flipped' secondary Y-axis
if (currSeriesName == "Capacity") {
var val = parseFloat(label.getCaption().getValue());
var newval = gblscale - val;
newval = newval.toFixed(0); // select decimal places in data point labels
label.getCaption().setValue(newval);
}
}
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03732 seconds