如何使用鼠标滚轮滚动我的gnatt highcharts

如何使用鼠标滚轮滚动我的gnatt highcharts,highcharts,scroll,Highcharts,Scroll,这是gnatt highcharts的链接,我想让它可以使用鼠标滚轮(不是主滚动条,而是highcharts的内置滚动条)进行滚动 我试过了,但是运气不好 这是gnatt highcharts的链接,我想让它可以使用鼠标滚轮(不是主滚动条,而是highcharts的内置滚动条)进行滚动 我试过了,但是运气不好 Highcharts.ganttChart('container', { title: { text: 'Gantt Chart with Progress Indicator

这是gnatt highcharts的链接,我想让它可以使用鼠标滚轮(不是主滚动条,而是highcharts的内置滚动条)进行滚动 我试过了,但是运气不好 这是gnatt highcharts的链接,我想让它可以使用鼠标滚轮(不是主滚动条,而是highcharts的内置滚动条)进行滚动 我试过了,但是运气不好

Highcharts.ganttChart('container', {
  title: {
    text: 'Gantt Chart with Progress Indicators'
  },
  scrollbar: {
          enabled: true
      },
      yAxis: {
          min: 0,
          max: 3,
          scrollbar:{
              enabled : true,
              showFull: false
          }
          },
  xAxis: {
    min: Date.UTC(2014, 10, 17),
    max: Date.UTC(2014, 10, 30),
    grid: {
            enabled: true,
            borderColor: 'rgba(0,0,0,0.3)',
            borderWidth: 1
          }
  },
  legend: {
    enabled: true
  },
  series: [{
    name: 'Project 1',
    data: [{
      name: 'Start prototype',
      start: Date.UTC(2014, 10, 18),
      end: Date.UTC(2014, 10, 25),
      completed: 0.25
    },{
      name: 'Start',
      start: Date.UTC(2014, 9, 18),
      end: Date.UTC(2014, 10, 25),
      completed: 0.25
    }, {
      name: 'Test prototype',
      start: Date.UTC(2014, 10, 27),
      end: Date.UTC(2014, 10, 29)
    }, {
      name: 'Develop',
      start: Date.UTC(2014, 10, 20),
      end: Date.UTC(2014, 10, 25),
      completed: {
        amount: 0.12,
        fill: '#fa0'
      }
    }, {
      name: 'Run acceptance tests',
      start: Date.UTC(2014, 10, 23),
      end: Date.UTC(2014, 10, 26)
    }]
  },
  {
    name: 'Project 2',
    data: [{
      name: 'Start prototype2',
      start: Date.UTC(2014, 10, 18),
      end: Date.UTC(2014, 10, 25),
      completed: 0.25
    }, {
      name: 'Test prototype2',
      start: Date.UTC(2014, 10, 27),
      end: Date.UTC(2014, 10, 29)
    }]
  }]
});

尝试此自定义功能,该功能应允许使用鼠标滚轮滚动图表

(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) / 20 * delta;
        newMin = extr.min + step;
        newMax = extr.max + step;
        console.log('max', extr.max)
        console.log('min', extr.min)

        if (newMin > axis.dataMin && newMax < axis.dataMax) {
          axis.setExtremes(newMin, newMax, true, false);

        }

      }

      stopEvent(event); // Issue #5011, returning false from non-jQuery event does not prevent default
      return false;
    });
  });
}(Highcharts));
(功能(H){
//内部功能
函数stopEvent(e){
如果(e){
如果(如默认){
e、 预防默认值();
}
如果(如停止播放){
e、 停止传播();
}
e、 取消气泡=真;
}
}
//包裹
H.wrap(H.Chart.prototype,“渲染”,函数(继续){
var图表=此,
mapNavigation=chart.options.mapNavigation;
继续。呼叫(图表);
//添加鼠标滚轮事件
H.addEvent(chart.container,document.onmousewheel===未定义的?'DOMMouseScroll':'mousewheel',函数(事件){
var delta,extr,step,newMin,newMax,axis=chart.yAxis[0];
e=图表.指针.规范化(事件);
//Firefox使用e.detail,WebKit和IE使用wheelDelta
δ=e.详图| |-(e.车轮δ/120);
δ=δ<0?1:-1;
if(chart.isInsidePlot(e.chartX-chart.plotLeft,e.chartY-chart.plotTop)){
extr=axis.getExtremes();
步长=(拉伸最大值-拉伸最小值)/20*delta;
newMin=extr.min+步长;
newMax=extr.max+步长;
console.log('max',extr.max)
console.log('min',extr.min)
if(newMin>axis.dataMin&&newMax
演示: