Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#2 | google_chart_tools-events-2.patch | 2.07 KB | KevinVb |
google_chart_tools-events.patch | 2.03 KB | KevinVb |
Comments
Comment #2
KevinVb CreditAttribution: KevinVb at Dropsolid commentedUpdate 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
Comment #3
wmfinnegan CreditAttribution: wmfinnegan commentedAny 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!