I built a line chart that fire an alert when the points are clicked, that works fine.
The problem is when I add the ‘explorer’ option (commented line, below) to enable the scroll zoom on the chart: the select
event doesn’t fire and the click doesn’t work anymore (fiddle)…
JavaScript
x
32
32
1
options = {
2
legend: 'none',
3
format: 'none',
4
hAxis: { textPosition: 'none', gridlines: { count: 0 } },
5
vAxis: { textPosition: 'none', gridlines: { count: 1 } },
6
curveType: 'function',
7
pointSize: 20,
8
9
10
};
11
12
chart = new google.visualization.LineChart(document.getElementById('chart_div'));
13
14
//If I enable this line, ZOOM works fine but the 'select' event don't work....
15
//options['explorer'] = {axis: 'horizontal',keepInBounds: true,maxZoomIn: 5.0};
16
17
chart.draw(data_estruturas, options);
18
19
//select event
20
google.visualization.events.addListener(chart, 'select', function(e) {
21
var selection = chart.getSelection();
22
if (selection.length > 0) {
23
var estrutura = data_estruturas.getValue(selection[0].row, 0)
24
alert(estrutura);
25
}
26
});
27
28
29
}
30
31
32
Please check this fiddle
Advertisement
Answer
Put the draw method after register the select event.
JavaScript
1
12
12
1
//select event
2
google.visualization.events.addListener(chart, 'select', function(e) {
3
var selection = chart.getSelection();
4
if (selection.length > 0) {
5
var estrutura = data_estruturas.getValue(selection[0].row, 0)
6
alert(estrutura);
7
}
8
});
9
10
//After set all options and register events draw the chart
11
chart.draw(data_estruturas, options);
12