Skip to main content



      Home
Home » Archived » BIRT » Problems with Variable Persistence
Problems with Variable Persistence [message #985688] Thu, 15 November 2012 12:12 Go to next message
Eclipse UserFriend
I'm having some problems with variable persistence in a report I'm building.

What I'm ultimately trying to do is fill a bar chart with sales data, sorting it by customer, then stick a marker line in there to display the average sales across the entire chart.

Here's what I'm doing to get there:

In Report initialize
reportContext.setPersistentGlobalVariable("m_fltTotalSales", "0.00");
reportContext.setPersistentGlobalVariable("m_intTotalCustomers", "0");


In DataSet onFetch
fltTotalSales = parseFloat(reportContext.getPersistentGlobalVariable("m_fltTotalSales")) + row["fltAmountOrdered"]; 
reportContext.setPersistentGlobalVariable("m_fltTotalSales", "" + fltTotalSales);

intTotalCustomers = parseInt(reportContext.getPersistentGlobalVariable("m_intTotalCustomers")) + 1;
reportContext.setPersistentGlobalVariable("m_intTotalCustomers", "" + intTotalCustomers);


In Chart onRender
function beforeGeneration( chart, icsc )
{
	importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
	importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
	importPackage(Packages.org.eclipse.birt.chart.model.attribute);
	importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
	
	var yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
	
	var rC = icsc.getExternalContext().getScriptable(); 
	
	var fltAverageSales = parseFloat(rC.getPersistentGlobalVariable("m_fltTotalSales")) / parseInt(rC.getPersistentGlobalVariable("m_intTotalCustomers"));
	
	var mlAverage = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(fltAverageSales));
	mlAverage.getLabel().getCaption().setValue("" + fltAverageSales);
	mlAverage.getLineAttributes().getColor().set(0,180,0);
	mlAverage.getLineAttributes().setStyle(LineStyle.SOLID_LITERAL);
	mlAverage.getLineAttributes().setThickness(2);
}


When I do a simple Preview, the marker line shows up, but only with the data from the first row. I gather that's normal in this situation (generation vs presentation and whatnot).

The problem comes when I View Report in Web Viewer because in that instance the marker line doesn't show up at all. It doesn't give me any errors. When I hardcode a value for fltAverageSales in beforeGeneration, the line shows up as expected, so it seems my variables aren't persisting like they should be.

It is my understanding that the way I'm doing the global variables should work across phases. Can anyone help out with this?

Note: I'm running Eclipse version 3.5.2 with BIRT version 2.5.2.
Re: Problems with Variable Persistence [message #985748 is a reply to message #985688] Thu, 15 November 2012 17:53 Go to previous messageGo to next message
Eclipse UserFriend
Initialize is called more than once. Move that script to the beforeFactory.

Jason
Re: Problems with Variable Persistence [message #985861 is a reply to message #985748] Fri, 16 November 2012 08:16 Go to previous message
Eclipse UserFriend
That worked perfectly. Thanks!

I'm still trying to wrap my head around when all these methods run.
Previous Topic:Real time charts
Next Topic:View BIRT report through a website
Goto Forum:
  


Current Time: Tue May 13 04:44:42 EDT 2025

Powered by FUDForum. Page generated in 0.06041 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top