Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Chart with 2 y-axis series - problem sorting
Chart with 2 y-axis series - problem sorting [message #1009592] Fri, 15 February 2013 06:01 Go to next message
Mimmo Rossi is currently offline 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 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 802
Registered: July 2009
Senior Member

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 #1010242 is a reply to message #1009876] Sat, 16 February 2013 19:36 Go to previous messageGo to next message
Mimmo Rossi is currently offline Mimmo Rossi
Messages: 108
Registered: February 2013
Senior Member
Hi,
yes if it's possible i need an example because i don't understand how reverse the value in the report (labels are dynamic, not fixed)
In the image there is my case:
http://dl.dropbox.com/u/47586998/img.JPG
What I want is that the series on the left have the value reversed (and consequently also the line).
Thanks
Re: Chart with 2 y-axis series - problem sorting [message #1010268 is a reply to message #1010242] Sat, 16 February 2013 21:08 Go to previous messageGo to next message
David Good is currently offline 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 #1010865 is a reply to message #1010268] Mon, 18 February 2013 06:14 Go to previous messageGo to next message
Mimmo Rossi is currently offline Mimmo Rossi
Messages: 108
Registered: February 2013
Senior Member
Hi David,
thanks for you help; there is some adjustment to do but it's a good start for my case. I'll let you know if it is positive or if i had other problems.
Thanks a lot.
icon14.gif  Re: Chart with 2 y-axis series - problem sorting [message #1010928 is a reply to message #1010865] Mon, 18 February 2013 08:47 Go to previous messageGo to next message
Mimmo Rossi is currently offline Mimmo Rossi
Messages: 108
Registered: February 2013
Senior Member
Very Happy
it works fine
Thanks a lot
Re: Chart with 2 y-axis series - problem sorting [message #1011001 is a reply to message #1010928] Mon, 18 February 2013 11:22 Go to previous messageGo to next message
Mimmo Rossi is currently offline Mimmo Rossi
Messages: 108
Registered: February 2013
Senior Member
Hi 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
Re: Chart with 2 y-axis series - problem sorting [message #1011018 is a reply to message #1011001] Mon, 18 February 2013 12:19 Go to previous message
Mimmo Rossi is currently offline Mimmo Rossi
Messages: 108
Registered: February 2013
Senior Member
Mimmo Rossi wrote on Mon, 18 February 2013 11:22
Hi 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?
Previous Topic:Is it possible to do Data Cube Scripting?
Next Topic:How to include and use libraries (rptlibrary file) in an Eclipse RCP application
Goto Forum:
  


Current Time: Sun May 19 14:02:40 EDT 2013

Powered by FUDForum. Page generated in 0.01715 seconds