highcharts 在销毁组件后从HighChart中删除扩展 Package 方法

s8vozzvw  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(220)
H.wrap(H.Chart.prototype, 'render', function (proceed) {
  var chart = this,

  proceed.call(chart);
  // Add the mousewheel event to make vertical scroll
  H.addEvent(chart.container,'mousewheel', function (event) {

    let delta, extr, step,  axis = chart.yAxis[0];

    let e = chart.pointer.normalize(event);
    // Firefox uses e.detail, WebKit and IE uses wheelDelta
    delta = e.detail || (e.wheelDelta / 120);
    delta = delta < 0 ? 1 : -1;
    extr = axis.getExtremes();
    const min = extr.min;
    const max = extr.max;
    const dataMax = extr.dataMax;
    if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop) && (min > 1 || (min < 1 && delta === 1)) && (max < dataMax || (max >= dataMax && delta === -1))) {
      step = (extr.max - extr.min) / 5 * delta;
      axis.setExtremes(extr.min + step, extr.max + step, true, false);
    }
    globalObj.stopEvent(event); // Issue #5011, returning false from non-jQuery event does not prevent default
    return false;
  });
})

我正在销毁ngOndestroy中的图表,当我再次返回到相同的组件时,之前创建的闭包仍然没有被销毁。当组件被销毁时,我需要删除wrap函数。

idv4meu8

idv4meu81#

根据@ppotaczek的建议,我删除了Wrap函数,并在创建图表后调用了add event函数。

const globalObj = this;
this.highchartRef = Highcharts.ganttChart('container', this.chartOptions, function(chartObj){
  globalObj.addMouseWheelEvent(chartObj); //Called my add mouse wheel event
});

相关问题