谷歌图表线与缩放和选择事件

时间:2017-11-09 18:49:31

标签: javascript charts javascript-events google-visualization zoom

我建立了一个折线图,在点击点时发出警报,工作正常。

问题是当我添加'explorer'选项(下面的注释行)以启用图表上的滚动缩放时:select事件不会触发e和点击不再起作用(fiddle)...

    options = {
      legend: 'none',
      format: 'none',
      hAxis: { textPosition: 'none', gridlines: { count: 0 } },
      vAxis: { textPosition: 'none', gridlines: { count: 1 } }, 
      curveType: 'function',
      pointSize: 20,


    };

    chart = new google.visualization.LineChart(document.getElementById('chart_div'));        

   //If I enable this line, ZOOM works fine but the 'select' event don't work....
   //options['explorer'] = {axis: 'horizontal',keepInBounds: true,maxZoomIn: 5.0};        

   chart.draw(data_estruturas, options);

    //select event
    google.visualization.events.addListener(chart, 'select', function(e) {
      var selection = chart.getSelection();     
      if (selection.length > 0) {
        var estrutura = data_estruturas.getValue(selection[0].row, 0)
        alert(estrutura);
      }
    });


}        

请检查此fiddle

1 个答案:

答案 0 :(得分:1)

在注册select事件后放置draw方法。

true

I updated your fiddle