Problems with Variable Persistence [message #985688] |
Thu, 15 November 2012 17:12  |
Chrono Hart Messages: 2 Registered: November 2012 |
Junior Member |
|
|
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02005 seconds