| Chart with 2 y-axis series - problem sorting [message #1009592] |
Fri, 15 February 2013 06:01  |
Mimmo Rossi Messages: 108 Registered: February 2013 |
Senior Member |
|
|
Hi all,
i have this problem: i have a chart with 2 series of y-axis, i would that these series have two different sorting of data, that is to say that the first series have the axis order from 0 to 9 (for example) and the second from 9 to 0.
It's possible?
Thanks in advance
|
|
|
| Re: Chart with 2 y-axis series - problem sorting [message #1009876 is a reply to message #1009592] |
Fri, 15 February 2013 17: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.
Regards,
Michael Williams
BIRT Exchange
Michael's BIRT Blog
|
|
|
|
| Re: Chart with 2 y-axis series - problem sorting [message #1010268 is a reply to message #1010242] |
Sat, 16 February 2013 21:08   |
David Good Messages: 33 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);
}
}
|
|
|
|
|
|
| Re: Chart with 2 y-axis series - problem sorting [message #1011018 is a reply to message #1011001] |
Mon, 18 February 2013 12:19  |
Mimmo Rossi Messages: 108 Registered: February 2013 |
Senior Member |
|
|
Mimmo Rossi wrote on Mon, 18 February 2013 11:22Hi David,
there is a "little" problem, on onmouseover marker of series lines the tooltip shown is with old value, can i set correct value? Otherwise i disable onmouseover event.
Thanks
i have solved in this way:
function beforeDrawDataPoint( dph, fill, icsc ){
var currSeriesName = dph.getSeriesValue();
if (currSeriesName == <nameSeriesToInvert>) {
var val = parseFloat(dph.getOrthogonalDisplayValue());
var newval = gblscale - val;
newval = newval.toFixed(0);
dph.setOrthogonalValue(newval);
}
}
Is the correct approach?
|
|
|
Powered by
FUDForum. Page generated in 0.02155 seconds