1

ポイントがクリックされたときに警告を発する折れ線グラフを作成しました。ズームと選択イベントのGoogleグラフライン

私は、チャートのスクロール、ズームを有効にする(下記コメント行、)「エクスプローラ」オプションを追加するときに問題がある:selectイベント(fiddle)火をいけないeandクリックはもういけない仕事...

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

はselectイベントを登録した後、drawメソッドを入れて確認してください。

//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); 
    } 
}); 

//After set all options and register events draw the chart 
chart.draw(data_estruturas, options); 

I updated your fiddle

関連する問題