我有一个这样的数组选项:
var options = {
chart: {
type: 'bar',
events: {
click: function(event) {
}
}
},
xAxis: {
categories: '',
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Aantal keer gekozen',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
//valueSuffix: ' aantal keer gekozen'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true,
color: 'black',
formatter: function() {
if (this.y === 0) {
return null;
} else {
return this.y;
}
}
},
stacking: 'normal'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
exporting: {
enabled: true
},
series: []
}
如您所见,我没有对点击功能做任何事情。
我在 foreach
中用 jQuery 创建 highcharts(所以我创建了多个图表)。
options.chart.renderTo = 'container' + index;
chart = new Highcharts.Chart(options);
现在如何像使用 renderTo
一样添加事件点击?
最佳答案
您可能需要阅读 javascript 中的闭包 - 否则您会为每个图表添加相同的事件。
另一种解决方案是为图表创建 id 数组,然后使用:options.chart.events.click = function() { window.location.href = '/path/' + ids[index];
;
关于javascript - Highcharts + 从 jquery 中的选项设置事件点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18781521/