Home
Analytics
Dynamic chart title
cypherdj
Hi,<br />
<br />
I'm using BIRT 2.2.2 and the chart title seems to be a static text. What I would like to do is include the selected parameter value in the title, e.g. <client>'s orders by month.<br />
<br />
I've briefly looked into the chart scripting, and it looks like I can get the chart title using:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
gcs.getChartModel().getTitle()
</pre>
<br />
However, there does not seem to be a setTitle method.<br />
<br />
Before someone suggests displaying the parameter in a report dynamic text instead, and hiding the chart title, those charts are embedded into a JSP page, so I'm extracting the chart only ;-)<br />
<br />
Any ideas?<br />
Rgds,<br />
Cedric
Find more posts tagged with
Comments
mwilliams
Hi Cedric,
In the chart script, you can use the following script to set the chart title:
function beforeGeneration( chart, icsc )
{
chart.getTitle().getLabel().getCaption().setValue(newTitle);
}
Hope this helps.
cypherdj
Lovely Michael, thanks, I was on the right track then ^_^
And how do I access my parameter from there? I just tried params["myParam"] as I normally would in the expression editor, but this gives me an error
ReferenceError: "params" is not defined. at line 12 of chart script
I also tried using reportContext.getParameterValue("UserName") and get a similar error.
I'm a bit rusty on the old scripting language, I've been busy with the API side of things recently ;-)
mwilliams
Cedric,
Your best bet is probably to store it in a persistentGlobalVariable, outside the chart and then recall that in your chart script with icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("varName");
Chris605
Hi Cedric, last week i've searched for the same answer, but i found a way my own:<br />
<br />
You have to click at the script button on a free place in your report. You should now be able to add these line:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.setPersistentGlobalVariable("title", params["tilte"].value)
</pre>
<br />
"title" is the name for the variable. Then you click your chart --> script and there you can get the variable, like:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeGeneration( chart, icsc ){
var title = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("title")
chart.getTitle().getLabel().getCaption().setValue(title)
}
</pre>
<br />
Then your parameter value should be the title of the chart.<br />
<br />
I've also found another way, if you don't want to use a parameter. I'm accessing my title from an SQL Statement. Let me know, if you need help for this way.<br />
<br />
Regards<br />
<br />
Chris
cypherdj
Thanks Chris,
it worked a charm.
Rgds,
Cedric