将事件处理程序附加到Google图表中的列图表 [英] attach event handler to Column Chart in google charts
问题描述
如何向Google图表(列图表)列名称(标签)添加事件侦听器。
例如,2004,2005,2006,2007等标签应该抛出事件。
$ b $b当用户点击列名(标签)时,事件(选择)应该是已触发。
How to add Event Listeners to google charts(Column Chart) column name(label).
For example, the lables such as 2004,2005,2006, 2007 should throw events.
When the user clicks on column name(label), event(select) should be triggered.
有一个规定,可以将事件监听器添加到可视化数据,而不是列标签。
books
当用户在可视化内 内选择一些数据时,触发名称为select的事件。事件不向侦听函数发送任何参数。
https://developers.google.com/chart/ interactive / docs / dev / events#The_Select_Event
There is a provision to add event listener to the visualisation data but not to the column label.
Fire an event with the name 'select' when the user selects some data within the visualization. The event does not send any arguments to the listening functions.
https://developers.google.com/chart/interactive/docs/dev/events#The_Select_Event
推荐答案
使用点击事件处理程序:
Use a "click" event handler:
google.visualization.events.addListener(chart, 'click', function(e) {
var match = e.targetID.match(/hAxis#\d#label#(\d)/);
if (match != null && match.length) {
var rowIndex = parseInt(match[1]);
// get the value from column 0 in the clicked row
var label = data.getValue(rowIndex, 0);
alert('You clicked on ' + label);
}
});
这篇关于将事件处理程序附加到Google图表中的列图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!