|
Re: How to create functions which can be reused in different chart script [message #898630 is a reply to message #898586] |
Thu, 26 July 2012 22:22 |
|
One way of doing this is to add the function to the report beforeRender
like:
function changeLabel ( label ){
label.getCaption().setValue(label.getCaption().getValue()+"Changed");
}
//set it as a global
reportContext.setGlobalVariable("changeLabel", changeLabel);
Then in chart script call it like:
function beforeDrawDataPointLabel( dph, label, icsc )
{
var cl
=icsc.getExternalContext().getScriptable().getGlobalVariable("changeLabel");
cl( label );
}
In chart script this line:
icsc.getExternalContext().getScriptable() is effectively the
reportContext object in normal report script
Jason
On 7/26/2012 1:13 PM, DONG YAO wrote:
> I have two charts on one report. Both charts need to do the same logic
> when drawing the xAxis label.
>
> Can I create one function and in both beforDrawAxisLabel call that
> function?
> How to do that?
>
> Thanks
|
|
|
|
|
Re: How to create functions which can be reused in different chart script [message #899142 is a reply to message #898845] |
Mon, 30 July 2012 16:19 |
|
Great question. The best way to do this is to create the js file in the
resource directory and then add the js file to the report as shown here:
http://www.eclipse.org/birt/phoenix/project/notable2.3.php#jump_8
If you add the js file this way it will make it available to the normal
report script environment meaning you can add a data element with the
expression getMyValue(); or in script for example on a label like:
this.text = reportContext.evaluate("getMyValue()");
Chart script context is not the same thing as reportContext but it does
have access to the reportContext. To call this same function from chart
script you could use:
function beforeDrawAxisTitle( axis, label, icsc )
{
label.getCaption().setValue(icsc.getExternalContext().getScriptable().evaluate("getMyValue()"));
}
This:
icsc.getExternalContext().getScriptable()
Is effectively the reportContext object.
Jason
On 7/27/2012 7:33 PM, DONG YAO wrote:
> Now I have a further question.
> If I have two reports and they both have the similar logic. How can I
> create script functions which could be shared by two reports?
>
> Thanks!
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09680 seconds