我如何在打字稿中的Angular2 highcharts中添加鼠标滚轮代码

How do i add mouse wheel code in Angular2 highcharts in typescript

我需要在 highcharts 垂直滚动条中添加鼠标滚轮。我得到了 fiddle http://jsfiddle.net/d3r8pb7c/ 中的代码,但该代码以 jQuery 格式编写。当我尝试以下列方式在打字稿中添加代码时,鼠标滚轮不起作用。

this.options = {
            chart: {

                events: {
                    wheel: function (event) {
                        var delta, extr, step, newMin, newMax, axis = this.xAxis[0];
                        var dataMax = this.xAxis[0].dataMax,
                            dataMin = this.xAxis[0].dataMin,
                            newExtrMin,
                            newExtrMax;

                        e = this.pointer.normalize(event);
                        delta = e.detail || -(e.deltaY / 120);
                        delta = delta < 0 ? 1 : -1;

                        if (this.isInsidePlot(e.chartX - this.plotLeft, e.chartY - this.plotTop)) {
                            extr = axis.getExtremes();
                            step = (extr.max - extr.min) / 5 * delta;

                            if ((extr.min + step) <= dataMin) {
                                newExtrMin = dataMin;
                                newExtrMax = extr.max;
                            } else if ((extr.max + step) >= dataMax) {
                                newExtrMin = extr.min;
                                newExtrMax = dataMax;
                            } else {
                                newExtrMin = extr.min + step;
                                newExtrMax = extr.max + step;
                            }

                            axis.setExtremes(newExtrMin, newExtrMax, true, false);

                        }

                        stopEvent(event); // Issue #5011, returning false from non-jQuery event does not prevent default
                        return false;
                    },
                }
            },

如果有人在 Highcharts angular2 打字稿中添加了鼠标滚轮事件,请帮助我。

首先,代码不依赖jQuery,所以没必要导入

我试图通过创建新模块并将其导入到组件文件中来包含附件 JSFiddle 中的代码。其实,我不知道你做错了什么,但我的例子运行良好。

import Stock from 'highcharts/modules/stock';
import Wheel from '../plugins/wheel-event'

Stock(Highcharts)
Wheel(Highcharts)

实例: https://stackblitz.com/edit/highcharts-cloning-chart-s7kztw