Currently I needed to be able to pass 'select', 'ready',... events to custom created charts.
This module is great but the events need to be added to the chart before the draw function is called.
See: https://developers.google.com/chart/interactive/docs/events

I wrote a small patch so everyone is able to bind his own custom events to the chart.
E.g:

 'events' => array(
    array(
        'event_name' => 'click',
        'func' => 'handleClick',
      ),
      array(
        'event_name' => 'select',
        'func' => 'handleSelect',
      ),
    ),

In google_chart_tools.js

if (element) {
   // Add listener
   chart[settings.chart[chartId]] = new google.visualization[settings.chart[chartId].chartType](element);
   // Add event listener
   var events = settings.chart[chartId].events;
   for (e in events) {
       var funct = window['handleReady'];
       google.visualization.events.addListener(chart[settings.chart[chartId]], events[e].event_name, window[events[e].func]);
    }
    chart[settings.chart[chartId]].draw(data, options);
}

I did not report this as a bug because it's a small feature.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KevinVb created an issue. See original summary.

KevinVb’s picture

Update my code. This way it passed the current chart and data to your own function.
Then you will be able to fetch the selected item and perform your custom actions

wmfinnegan’s picture

Any chance you could share a little more about how you added the custom events? Was it through hook_draw_chart_alter()? Or a jQuery snippet?

I'm trying to set up exporting charts as a PNG (https://developers.google.com/chart/interactive/docs/printing#overview) but am having trouble getting chart.getImageURI() to work and was hoping this event handler approach could help.

Thanks!