我使用highcharts並想插入點擊復位變焦按鈕事件的一些邏輯插入邏輯,但我沒有找到一個很好的辦法。搜索在StackOverflow上,發現了最好的答案是:highcharts如何捕捉並點擊復位變焦按鈕事件
event.srcElement.firstChild.data == "Reset zoom"
但這種方式有1點的問題,當我們點擊「重置縮放」按鈕角落的事件將不會被觸發。只有當我們點擊文本「重置縮放」的tSpan時,這種方式纔有效。想問問是否有另一種解決方案。
我使用highcharts並想插入點擊復位變焦按鈕事件的一些邏輯插入邏輯,但我沒有找到一個很好的辦法。搜索在StackOverflow上,發現了最好的答案是:highcharts如何捕捉並點擊復位變焦按鈕事件
event.srcElement.firstChild.data == "Reset zoom"
但這種方式有1點的問題,當我們點擊「重置縮放」按鈕角落的事件將不會被觸發。只有當我們點擊文本「重置縮放」的tSpan時,這種方式纔有效。想問問是否有另一種解決方案。
Highcharts提供了一個叫做選擇
chart:{
events: {
selection: function() { /* your code here */ }
}
}
情況下,本琴會幫助你http://jsfiddle.net/M7cfm/
只需使用setExtremes事件,請參閱:http://jsfiddle.net/3bQne/621/
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
zoomType: 'x'
},
xAxis: {
events: {
setExtremes: function (e) {
if(typeof e.min == 'undefined' && typeof e.max == 'undefined'){
console.log('reset zoom clicked');
} else {
console.log('zoom-in');
}
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0]
}]
});
我想知道爲什麼我的代碼是不是工作,並感謝您的回答,我意識到,當您按下「Reset Zoom」按鈕時,event.yAxis和event.xAxis會回到未定義狀態。謝謝! – Termato