Highcharts / highstock鼠标滚轮滚动在y轴上保持滚动

时间:2016-09-22 12:36:37

标签: javascript highcharts highstock

我正在使用asp.net MVC 5,我正在使用dot net highcharts来显示我的数据

我想在缩放时在y轴上添加鼠标滚轮,所以我发现了一段代码

(function (H) {

    //internal functions
    function stopEvent(e) {
        if (e) {
            if (e.preventDefault) {
                e.preventDefault();
            }
            if (e.stopPropagation) {
                e.stopPropagation();
            }
            e.cancelBubble = true;
        }
    }

    //the wrap
    H.wrap(H.Chart.prototype, 'render', function (proceed) {
        var chart = this,
          mapNavigation = chart.options.mapNavigation;

        proceed.call(chart);

        // Add the mousewheel event
        H.addEvent(chart.container, document.onmousewheel === undefined ? 'DOMMouseScroll' : 'mousewheel', function (event) {

            var delta, extr, step, newMin, newMax, axis = chart.yAxis[0];

            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;

            if (chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
                extr = axis.getExtremes();
                step = (extr.max - extr.min) / 5 * delta;
                axis.setExtremes(extr.min + step, extr.max + step, true, false);
            }

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

但是有一个问题

  1. 滚轮无限次滚动
  2. 我希望它只在我处于缩放状态时启用
  3. JsFiddle链接将在评论部分

    任何帮助将不胜感激

0 个答案:

没有答案