Event handlers don't contain a reference to the chart they are attached to.
If you want to create a generic event handler that can handle multiple
charts, give the function a chart parameter and then pass the current chart
to the function inside the event handler:
function eventHandler (chartObj) {
// do something with chartObj
}
google.visualization.events.addListener(chart, 'select', function () {
eventHandler(chart);
});
Don't make the columns and series options generic, as they contain data
that is unique to the chart which they are assigned to. You can make
objects that contain references to the (distinct) series and columns of
multiple charts, but don't use one set of columns and series for all
charts, eg:
var series = {
chart_1: {...},
chart_2: {...}
}
On Thursday, June 6, 2013 9:47:41 AM UTC-4, A. Farber wrote:
>
> Hello Andrew,
>
> On Tue, Jun 4, 2013 at 7:13 PM, asgallant <[email protected]<javascript:>
> > wrote:
>
>> I wrote a hack that shows/hides series by clicking on legend labels
>> (hidden series are greyed out in the legend):
>> http://jsfiddle.net/asgallant/6gz2Q/.
>
>
> thank you for the code!
>
> Because I have multiple charts at my Perl-generated web pages I'd like to
> move the var columns=[], var series={} part into the "select" listener.
>
> My problem is: how to access the currently selected chart and esp. its
> data?
>
> Is a ref to it passed within "select" event?
>
> I've added argument to the listener:
> google.visualization.events.addListener(chart, 'select', function
> (event) {
> console.dir(event);
>
> but it prints: null
>
> Regards
> Alex
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.