highcharts 在多个图表之间同步缩放

k4emjkb1  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(191)

在下面的小提琴中,我如何同步所有三个图表的x轴缩放?谢谢。
小提琴:https://jsfiddle.net/mbfhqsLx/62/

function syncZoom(target, e) {
        var chart = $(target).highcharts(),
            min, max;
        min = e.min === null ? e.dataMin : e.min;
        max = e.min === null ? e.dataMax : e.max;
        syncing = true;
        chart.xAxis[0].setExtremes(min, max);
        syncing = false;          
}
gmol1639

gmol16391#

You can use afterSetExtremes() to implement synchronized zoom:

xAxis: {
    events: {
      afterSetExtremes: function(event) {
        Highcharts.charts.forEach(chart => {
          chart.xAxis[0].setExtremes(event.min, event.max);
        })
      }
    }
  }

Demo:https://jsfiddle.net/BlackLabel/w5890cen/
API Reference:https://api.highcharts.com/highcharts/xAxis.events.afterSetExtremes

相关问题