我需要處理標尺上的onclick事件。我沒有在Google圖表文檔中找到Gauges上註冊事件的示例。如何將onclick事件添加到Google Chart的Gauge?
我曾嘗試以下:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart","gauge"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'LABEL');
data.addColumn('number', 'TOTAL');
data.addRows(1);
data.setValue(0, 0, 'Speed');
data.setValue(0, 1, 240);
var gaugeOptions = {min: 0, max: 280, yellowFrom: 200, yellowTo: 250, title: 'Company Performance', redFrom: 250, redTo: 280, minorTicks: 5};
var gauge = new google.visualization.Gauge(document.getElementById('gauge_div'));
gauge.draw(data, gaugeOptions);
google.visualization.events.addListener(gauge, 'select', function() {
alert("Here");
});
}
</script>
</head>
<body>
<div id="gauge_div"></div>
</body>
</html>
此外,我試圖用jQuery添加onclick事件格「gauge_div」但如果我點擊div的邊界,而不是在計它只。
是這個作品,如果你只有一個計,但是當你有使許多計我想要得到的onclick事件並識別發件人。 –
在這種情況下,您可能想了解如何從iframe捕獲點擊事件。 http://stackoverflow.com/questions/1609741/how-to-add-click-event-to-a-iframe-with-jquery – chris