Home
Analytics
Dynamic Chart Title
bsteuhl
I am new to BIRT and have a question regarding chart title. Can someone tell me how to insert a report parameter in the chart title. I know I can write a script to declare a variable set to this.getreportelement.("element name") and then assign that variable a static value = getTitle().getCaption().SetValue("Some Text"). However, I can not figure out how to assign a report parameter to the chart title. It appears as though I can not use params["rptparameter"], so how would I go about this. I read something about reportcontext, but not an in depth example so I am stuck. Thank you.
Find more posts tagged with
Comments
Virgil Dodson
Hi bsteuhl,
Try something like this:
function beforeGeneration(chart, icsc)
{
var title = icsc.getExternalContext().getScriptable().getParameterValue("chartTitleParam")
chart.getTitle().getLabel().getCaption().setValue(title)
}
Virgil
bsteuhl
Thanks Virgil. Everything worked perfectly.
One other question - why when I type in getscriptable(). the function getParameterValue() does not appear in the available list? Also, where do I read up on all of the scripts/functions that are available in BIRT. Thanks.
Virgil Dodson
I'm not sure of why the getParameterValue function does not appear in the context help.<br />
<br />
As for scripting help, there is a spot in the FAQ at <a class='bbc_url' href='
http://www.birt-exchange.com/modules/mediawiki/index.php/BIRT:Scripting'>http://www.birt-exchange.com/modules/mediawiki/index.php/BIRT:Scripting</a>
; on scripting.<br />
<br />
I also spend some time in the doc section of the site... some direct links are:<br />
Chapter 22 - Using Scripting in a Report Design<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/documentation/BIRT_220/wwhelp/wwhimpl/js/html/wwhelp.htm?href=birt-23-1.html'>http://www.birt-exchange.com/documentation/BIRT_220/wwhelp/wwhimpl/js/html/wwhelp.htm?href=birt-23-1.html</a><br
/>
<br />
Chapter 25 - Scripting reference<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/documentation/BIRT_220/wwhelp/wwhimpl/js/html/wwhelp.htm?href=birt-26-1.html'>http://www.birt-exchange.com/documentation/BIRT_220/wwhelp/wwhimpl/js/html/wwhelp.htm?href=birt-26-1.html</a><br
/>
<br />
Report Scripting API Reference<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/documentation/BIRT_220/EngineJavadoc/enginescript/api/index.html'>http://www.birt-exchange.com/documentation/BIRT_220/EngineJavadoc/enginescript/api/index.html</a>
;
Ingoos
<blockquote class='ipsBlockquote' data-author="'Virgil'" data-cid="28294" data-time="1194994581" data-date="13 November 2007 - 03:56 PM"><p>
Hi bsteuhl,<br />
Try something like this:<br />
<br />
function beforeGeneration(chart, icsc)<br />
{<br />
var title = icsc.getExternalContext().getScriptable().getParameterValue("chartTitleParam")<br />
chart.getTitle().getLabel().getCaption().setValue(title)<br />
}<br />
Virgil<br /></p></blockquote>
<br />
hi, this script work for title, but i'm trying same thing for series title in pie chart ... and can't figure out
... i tried with 'SeriesIdentifier' without any luck ... can anyone help me
tnx
kclark
Hi Ingoos! You would need to do this from beforeDrawSeriesTitle()<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawSeriesTitle( series, label, icsc )
{
var title = icsc.getExternalContext().getScriptable().getParameterValue("chartTitleParam")
label.getCaption().setValue(title)
}</pre>
Ingoos
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="115322" data-time="1363961016" data-date="22 March 2013 - 07:03 AM"><p>
Hi Ingoos! You would need to do this from beforeDrawSeriesTitle()<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
function beforeDrawSeriesTitle( series, label, icsc )
{
var title = icsc.getExternalContext().getScriptable().getParameterValue("chartTitleParam")
label.getCaption().setValue(title)
}</pre></p></blockquote>
<br />
thanks
... working well
kclark
No problem! Let us know if you have anymore questions!
ravikantb
<p>Hi,</p><p> </p><p>My requirement is similar except the fact that I change the report parameter dynamically and then want to put its new value as the chart title dynamically.</p><p> </p><p>To be more detailed: I have a data set which fires a sql query to give me an id. This id is then used in another sql query which is used to render the chart. This is achieved by keeping the id in a report parameter. Now I want the chart to have this id as the chart title.</p><p> </p><p>I have tried the approaches outlined above but the title always picks the default value of the report parameter instead of new value.</p><p>Any idea about what I be missing here?</p><p> </p><p>Please let me know if you want more details.</p><p> </p><p>Thanks,
Ravikant Bhargava</p>
kclark
<p>What version of BIRT are you using? Can you recreate this with the sample db and post the rptdesign?</p>
ravikantb
<p>I'm using BIRT as an Eclipse IDE plug-in. The manifest file for the plug-in says:</p><p>Bundle-Version: 3.7.2.v20120213</p><p> </p><p>I will try to recreate the same scenario and post the rptdesign file here. Will let you guys know in case I get stuck.</p><p> </p><p>Thanks for your time and help.</p><p> </p><p>Regards,</p><p>Ravikant Bhargava</p>
ravikantb
<p>Hi,</p><p> </p><p>Apologies for the delay but I was moved to a different project for some time.</p><p> </p><p>PFA a sample design file which recreates above mentioned behavior.</p><p> </p><p>Here, the 'onCreate' event of row in 'customernumber' table assigns a value to a report parameter by the name 'NewParameter' (this is done using script).</p><p>Now another data set query renders the graph using the 'customernumber' obtained in the above mentioned table. I want this chart to have the same 'customernumber' as its title. To do this in 'beforeRendering' event of the chart I get the value of the 'NewParameter' and assign it to the chart title (again using script). But it always picks the default value of the 'NewParameter'.</p><p> </p><p>I created this sample by modifying another sample code. Please let me know if I should simplify it further or if you need any other input from me.</p><p> </p><p>Thanks,</p><p>Ravikant Bhargava</p>