How do I detect a zoom event in highcharts?

后端 未结 3 1286
清歌不尽
清歌不尽 2021-02-05 10:57

Is it possible to detect a zoom event in 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

相关标签:
3条回答
  • 2021-02-05 11:10

    Have you tried going through the Highcharts API?

    You may want to look @ xAxis.events.setExtremes And/Or chart.events.selection

    0 讨论(0)
  • 2021-02-05 11:21

    You want to look at the redraw event as well. When you zoom, the chart is redrawn to reflect the changes. chart.events.redraw

    events: {
        redraw: function(){
            console.log(this.xAxis);
            console.log(this.yAxis);
        }
    }
    
    0 讨论(0)
  • 2021-02-05 11:31

    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

    0 讨论(0)
提交回复
热议问题