Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Graph contains 4 marker lines, some not needed(BIRT marker lines in beforeDrawMarkerLine)
Graph contains 4 marker lines, some not needed [message #1027927] Wed, 27 March 2013 16:00 Go to next message
Olly   is currently offline Olly Friend
Messages: 61
Registered: June 2010
Location: Florida
Member
I'm currently using BIRT 3.7. I've got a report template that has 4 marker lines that are threshold lines. When the report is run, the query result may or may not contain all of these thresholds. Some may be null. In the case that the value is null, is there a way to not draw the line? In the template I have a working script that sets the value of each marker line under the use case where all marker lines contain valid values.
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
function beforeDrawMarkerLine( axis, markerLine, context) 
{
	target = context.getExternalContext().getScriptable().getPersistentGlobalVariable("COUNTER");
	if(target == 1)
	{
		target = context.getExternalContext().getScriptable().getPersistentGlobalVariable("MAX_THRESHOLD");
		markerLine.setValue(NumberDataElementImpl.create(target));
		markerLine.getLabel().getCaption().setValue("Max Red " + target);
		context.getExternalContext().getScriptable().setPersistentGlobalVariable("COUNTER", "2");
	}
	else if(target == 2)
	{
		target = context.getExternalContext().getScriptable().getPersistentGlobalVariable("MIN_THRESHOLD");
		markerLine.setValue(NumberDataElementImpl.create(target));
		markerLine.getLabel().getCaption().setValue("Min Red " + target);
		context.getExternalContext().getScriptable().setPersistentGlobalVariable("COUNTER", "3");
	}
	else if(target == 3)
	{
	/*
		target = context.getExternalContext().getScriptable().getPersistentGlobalVariable("MAX_THRESHOLD_YELLOW");
		markerLine.setValue(NumberDataElementImpl.create(target));
		markerLine.getLabel().getCaption().setValue("Max Yellow " + target);*/
		context.getExternalContext().getScriptable().setPersistentGlobalVariable("COUNTER", "4");
	}
	else
	{
	/*
		target = context.getExternalContext().getScriptable().getPersistentGlobalVariable("MIN_THRESHOLD_YELLOW");
		markerLine.setValue(NumberDataElementImpl.create(target));
		markerLine.getLabel().getCaption().setValue("Min Yellow " + target);*/
		context.getExternalContext().getScriptable().setPersistentGlobalVariable("COUNTER", "1");
	}
	
}
Is there any way to check at this point that if the value of the threshold is null then don't draw it? I can set the global variable to a flag value and check it for the flag in another method if need be. I've been looking through some API's http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.birt.chart.doc.isv%2Fchart%2Fapi%2Forg%2Feclipse%2Fbirt%2Fchart%2Fmodel%2Fcomponent%2FMarkerLine.html but I'm still looking for a solution. Any help is appreciated.
Re: Graph contains 4 marker lines, some not needed [message #1028084 is a reply to message #1027927] Wed, 27 March 2013 20:23 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

why not just create the marker lines dynamically in the beforeGeneration event:
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 chart = icsc.getChartInstance();
var yAxis = chart.getAxes().get(0).getAssociatedAxes().get(0);
var base_value = icsc.getExternalContext().getScriptable().getGlobalVariable("baseline");
var target_value = icsc.getExternalContext().getScriptable().getGlobalVariable("target");


target_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(target_value));
target_ml.getLabel().getCaption().setValue("Target");
target_ml.getLineAttributes().getColor().set(32,145,245);

base_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(base_value));
base_ml.getLabel().getCaption().setValue("Baseline");
base_ml.getLineAttributes().getColor().set(0,0,0);
}
Re: Graph contains 4 marker lines, some not needed [message #1028757 is a reply to message #1028084] Thu, 28 March 2013 17:43 Go to previous messageGo to next message
Olly   is currently offline Olly Friend
Messages: 61
Registered: June 2010
Location: Florida
Member
Great suggestion, it works well. Only thing remaining I need is how to set the positioning of the label caption. Since there are 4 lines I want to set one top right, another one bottom right, another one top left, and the last bottom left. Can you help me with this as well?
Re: Graph contains 4 marker lines, some not needed [message #1029443 is a reply to message #1028757] Fri, 29 March 2013 17:51 Go to previous messageGo to next message
Olly   is currently offline Olly Friend
Messages: 61
Registered: June 2010
Location: Florida
Member
I was able to position the labels by using
Anchor.get(Anchor.NORTH_EAST);
I changed the location of the labels as needed.
Re: Graph contains 4 marker lines, some not needed [message #1029594 is a reply to message #1029443] Fri, 29 March 2013 22:44 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Glad you got it.
Previous Topic:Birt Viewer: Firts launch takes a long time
Next Topic:PDFRender - OutputStream not closed ?
Goto Forum:
  


Current Time: Wed Oct 09 20:24:34 GMT 2024

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

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

Back to the top