getSelection and many charts

41 views
Skip to first unread message

Ricardo Coelho

unread,
Jul 9, 2012, 10:54:39 AM7/9/12
to Google Visualization API
Hi,
First, sorry for my english.

I understand how to use "addListener" but in every examples i found,
it is with one chart.
How can I do with many chart ? how can i know which one as been
clicked ?

So i can't use "getSelection". I need to use the same callback
function for every chart.

Thanks in advance

asgallant

unread,
Jul 9, 2012, 12:48:03 PM7/9/12
to google-visua...@googlegroups.com
The easiest way I found to manage using the same event listener function for multiple charts is to put the charts in an array and loop over the array, assigning an event listener for each chart:

// charts is an array of charts
for (var 0charts.lengthi++{
    google.visualization.events.addListener(charts[i]'ready'(function (x{
        return function ({
            // use charts[x] to access the specific chart
        }
    })(i);
} 

Note that you need to use a closure around the function to map each instance of "i" to the handler function for that chart.

Ricardo Coelho

unread,
Jul 10, 2012, 4:15:29 AM7/10/12
to google-visua...@googlegroups.com
Perfect !! Thank you !!
Reply all
Reply to author
Forward
0 new messages