*Highcharts* 如何获取缩放框的最小值和最大值

*Highcharts* How to get the min and max value of the zoom box

我通过设置 zoomType: 'xy' 在 highcharts 中使用缩放功能,想问一下当我使用鼠标 select 时如何找到缩放框 x 轴上的最小值和最大值变焦位置。我尝试使用 getExtremes() :

events: {
    afterSetExtremes: function () {
        min = parseFloat(this.getExtremes().min);
        max = parseFloat(this.getExtremes().max);
    }
}

但返回的最小值和最大值似乎是缩放后整个图表屏幕的值,而不是我select缩放的框。

您可以使用 chart.events.selection 事件来获取此信息。例如:

chart: {
    events: {
        selection: function(event) {
            if(event.xAxis != null)
                console.log("selection: ", event.xAxis[0].min, event.xAxis[0].max);
            else
                console.log("selection: reset");
        }
    },
    zoomType: 'xy'
}

有关结果的演示和记录,请参阅 this JSFiddle