Catch panning event in Highcharts

2019-06-14 13:21发布

问题:

Is it possible to catch event when user is panning on chart?

I've Highcharts options set to:

chart: {
  panning: true,
  panKey: 'shift',
  events: {}
}

In events object, selection is working. In the documentation, there's nothing about pane event.

Is there a way to catch this event anyway?

回答1:

Highcharts doesn't provide that kind of event by default.

The workaround for this is to wrap the core pan function:

(function(H) {
  H.wrap(H.Chart.prototype, 'pan', function(proceed) {
    console.log("panning...");
    proceed.call(this, arguments[1], arguments[2]);
  });
})(Highcharts);

Live demo: http://jsfiddle.net/kkulig/gn8gmsn0/

Docs reference: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts