简体   繁体   English

如何检测 highcharts 中的缩放事件?

[英]How do I detect a zoom event in highcharts?

Is it possible to detect a zoom event in Highcharts?是否可以在 Highcharts 中检测缩放事件? My use case is that I have some state external to the chart, and when the user zooms in on part of it I want to detect what the new time range on the x-axis is and update the corresponding external state.我的用例是我在图表外部有一些状态,当用户放大其中的一部分时,我想检测 x 轴上的新时间范围是什么并更新相应的外部状态。

Have you tried going through the Highcharts API ?你试过通过Highcharts API吗?

You may want to look @ xAxis.events.setExtremes And/Or chart.events.selection你可能想看看@ xAxis.events.setExtremes和/或chart.events.selection

You want to look at the redraw event as well.您还想查看重绘事件。 When you zoom, the chart is redrawn to reflect the changes.缩放时,图表会重新绘制以反映更改。 chart.events.redraw chart.events.redraw

events: {
    redraw: function(){
        console.log(this.xAxis);
        console.log(this.yAxis);
    }
}

I found a way using redraw global event:我找到了一种使用重绘全局事件的方法:

 { redraw: function(event) { if ( (event ? .target ? .axes[0] && event ? .target ? .axes[0].max !== event ? .target ? .axes[0].oldMax) || (event ? .target ? .axes[1] && event ? .target ? .axes[1].max !== event ? .target ? .axes[1].oldMax)) { // Here you can be sure the this is closer to a zoom event... almost, because it also detect drag on the map :( } } }

I just want to leave this here because I decide to use something else but my future self might need it :D我只想把它留在这里,因为我决定使用其他东西,但我未来的自己可能需要它:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM