我在使用Angular 7中的google.visualization.ChartWrapper在Google Maps图表上添加onclick事件侦听器时遇到问题
该事件不起作用,我没有收到任何错误或日志。该地图将绘制精美,并且“就绪”的侦听器也像吊饰一样起作用。
官方文档:https://developers.google.com/chart/interactive/docs/reference#chartwrapperobject
//My Html-Element
<div id="chart"></div>
//I Initilize the ChartWrapper
map: google.visualization.ChartWrapper = new google.visualization.ChartWrapper({
chartType: 'Map',
dataTable: [["Latitude", "Longitude", "Name"], [lat, long, company]],
options: {
showTooltip: true,
enableScrollWheel: true,
useMapTypeControl: true,
tooltip: { isHtml: true }
},
containerId: 'chart'
});
//In NgOnInit im loading the package and call my draw function
ngOnInit() {
google.charts.load('current', { 'packages': ['map'] });
google.charts.setOnLoadCallback(this.drawMap.bind(this));
}
drawMap() {
//I set the ready eventlistener
google.visualization.events.addListener(this.map,'ready',this.onReady.bind(this));
this.map.draw();
}
onReady() {
//This Event works and i get the alert
alert('Ready');
google.visualization.events.addListener(this.map.getChart(), 'click', this.onClick);
}
onClick($event) {
//This never works
alert('Click');
}
我希望任何人都可以帮助
答案 0 :(得分:0)
根据Map
图表的events documentation,
没有'click'
事件。
尝试使用'select'
代替...
google.visualization.events.addListener(this.map.getChart(), 'select', this.onClick);