Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Chart scripting with report variables
Chart scripting with report variables [message #729918] Tue, 27 September 2011 09:37 Go to next message
john mcteague is currently offline john mcteague
Messages: 15
Registered: July 2009
Junior Member
I am using BIRT 2.6.2, I have a chart and I want to add some client side scripting so that when the user clicks anywhere on the chart it calls some javascript. To do this I am using the interactivity option for the "Chart Area"

My chart renders inside a table, each row of the table produces a chart and the chart data set binding refers to a column in the table's dataset, in this case an organisational department.

The BIRT designer does not let me reference the parent dataset so I cannot create a script that knows about the current organisational department, my only options are Report Parameters, native javascript funcs, operators and variables.

One idea I had was to create a report variable called currentDept that would be updated on each row of the table so that it contains the correct department and then use the variable in my script since Variables are exposed to the javascript editor for charts.

Therefore for the Mouse Click Event on the chart area, I invoke the following script:

alert(vars["currentDept"])

But in the resulting HTML, I actually get alert(vars["currentDept"]) rendered in the HTML, the variable is not resolved.

If it had been a report parameter, for example alert('params["SomeParam"].value'), it would have resolved the param and I would have valid javascript.

Is this a bug, if so is there a better way of getting the current row values for my chart in order to build a javascript function?

Thanks,
John
Re: Chart scripting with report variables [message #730105 is a reply to message #729918] Tue, 27 September 2011 16:02 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

John,

The issue is that the client side script in the chart does not have
access to those variables. To get around this you can use some script
on the table to store a key to value pair that references one of the
values available in the chart. For example assume I have a category
value and and two series but I only use one series in the chart. I can
load an array of cat to series2 values and then use a script tag to
convert this array to client side js array.

Table oncreate
mygenarray = [];
mygenarrayser2 = [];
i=0;

Table detail on create:
var var1 = this.getRowData().getColumnValue("series2");
var var2 = this.getRowData().getColumnValue("category");
mygenarray[i]=var2;
mygenarrayser2[i]=var1;
i++;

//Text element at bottom of report
<script language="JavaScript">

var mycatarray = <VALUE-OF>var finals = "[ ";
for( var ii=0; ii < mygenarray.length; ii++){
if( ii == 0 ){
finals = finals + "'" + mygenarray[ii] + "' ";
}else{
finals = finals + ",'" + mygenarray[ii] + "' ";
}
}
finals = finals + " ];"</VALUE-OF>

var myserarray = <VALUE-OF>var finals = "[ ";
for( var ii=0; ii < mygenarrayser2.length; ii++){
if( ii == 0 ){
finals = finals + mygenarrayser2[ii];
}else{
finals = finals + "," + mygenarrayser2[ii];
}
}
finals = finals + " ];"</VALUE-OF>


function ShowEventData(evt, categoryData, valueData, valueSeriesName,
legendItemText, legendItemValue, axisLabel) {


//find value of second series
for( var j=0; j < mycatarray.length; j++ ){
if( mycatarray[j] == categoryData){
alert(myserarray[j]);
break;
}
}
}
</script>

I can then cal the ShowEventData client side script from my chart value
series interactivity like:
Mouse Click
Invoke Script
ShowEventData(evt, categoryData, valueData, valueSeriesName,
legendItemText, legendItemValue, axisLabel);

See attached example. Also have a look at this post:
http://birtworld.blogspot.com/2010/05/more-on-chart-interactivity.html

Jason



On 9/27/2011 5:37 AM, john mcteague wrote:
> I am using BIRT 2.6.2, I have a chart and I want to add some client side
> scripting so that when the user clicks anywhere on the chart it calls
> some javascript. To do this I am using the interactivity option for the
> "Chart Area"
>
> My chart renders inside a table, each row of the table produces a chart
> and the chart data set binding refers to a column in the table's
> dataset, in this case an organisational department.
>
> The BIRT designer does not let me reference the parent dataset so I
> cannot create a script that knows about the current organisational
> department, my only options are Report Parameters, native javascript
> funcs, operators and variables.
>
> One idea I had was to create a report variable called currentDept that
> would be updated on each row of the table so that it contains the
> correct department and then use the variable in my script since
> Variables are exposed to the javascript editor for charts.
>
> Therefore for the Mouse Click Event on the chart area, I invoke the
> following script:
>
> alert(vars["currentDept"])
>
> But in the resulting HTML, I actually get alert(vars["currentDept"])
> rendered in the HTML, the variable is not resolved.
> If it had been a report parameter, for example
> alert('params["SomeParam"].value'), it would have resolved the param and
> I would have valid javascript.
>
> Is this a bug, if so is there a better way of getting the current row
> values for my chart in order to build a javascript function?
>
> Thanks,
> John
Previous Topic:Websphere+Birt 3.7: Report generation aborts after 1 minute. Timeout?
Next Topic:XML Data-Source request method
Goto Forum:
  


Current Time: Mon Sep 22 12:20:07 GMT 2014

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

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