It depends. If you add an event listener inside a 'ready' event listener
for the dashboard, then every time the dashboard fires a 'ready' event,
another instance of the event listener will be created. Sometimes this is
ok, sometimes you don't want this at all. There is no one "best" way.
Usually, the only thing that causes a dashboard to fire a 'ready' event is
when you call the draw method. When this happens, all existing dashboard
elements are destroyed (I assume cleanly) by the API and redrawn. Any
event handlers you had put in place *on the charts or controls themselves* (ie,
chart or control objects, not ChartWrappers or ControlWrappers) are
destroyed along with the elements, and thus would need to be recreated.
If there is anything you don't want to instantiate a second time, you can
destroy the 'ready' event listener:
var readyListener = google.visualization.events.addListener(dash, 'ready',
function () {
// do some stuff
// then destroy this event listener
google.visualization.events.removeListener(readyListener);
});
You can create multiple 'ready' event listeners for the dashboard, to
separate out things you only want to instantiate once and things that need
to be reinstantiated when the dashboard is redrawn.
On Friday, June 22, 2012 4:49:23 AM UTC-4, Peetzer wrote:
>
> Sometimes after ready event of dashboard, select or other listeners can
> only be used on other controls.
>
> Should the google.visualization.events.addListener be called only once on
> a control or is this handled internally (getKey()) ?
>
> In other words, is the same listener is not added multiple times when
> calling google.visualization.events.addListener again?
>
> Should the listeners always be removed (removeListener) on unload to
> prevent memory leakage?
>
> Regards Peter
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/9Q_ZR6mb_CUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.