【问题标题】:Highcharts: Tooltip delay before displayHighcharts:显示前的工具提示延迟
【发布时间】:2016-09-27 09:03:00
【问题描述】:

在我的 highchart 上,在显示系列工具提示之前我需要延迟。

我用定时器定义了一个新的刷新函数来实现它。如果计时器准备好了,我会检查鼠标位置。如果它移动得不多,则应该出现工具提示。

function (H) {
              var timer = [];
              var mousePosition = {
                  x: 0,
                  y: 0
              };

              window.addEventListener("mousemove", function (event) {
                  mousePosition.x = event.pageX;
                  mousePosition.y = event.pageY;
              });

              var getMousePositionX = function () {
                  return mousePosition.x;
              };

              var clearTimer = function () {
                  timer = [];
              }

              H.wrap(H.Tooltip.prototype, 'refresh', function (proceed) {
                  var mousePosX = getMousePositionX();
                  var delayForDisplay = this.chart.options.tooltip.delayForDisplay ? this.chart.options.tooltip.delayForDisplay : 1000;
                  timer[timer.length+1] = window.setTimeout(function () {
                      var currMousePosX = getMousePositionX();
                      if ((mousePosX >= currMousePosX - 5 && mousePosX <= currMousePosX + 5)) {
                          this.proceed.apply(this.tooltip, this.refreshArguments);
                          clearTimer();
                      }
                  }.bind({
                      refreshArguments: Array.prototype.slice.call(arguments, 1),
                      chart: this.chart,
                      tooltip: this,
                      clearTimer: clearTimer,
                      proceed: proceed
                  }), delayForDisplay);
              });
          };

我遇到的问题是,悬停全息也有延迟。

这是一个示例:JSFiddle

有解决这个问题的办法吗?

【问题讨论】:

标签: javascript highcharts tooltip


【解决方案1】:

您可以根据您的标准 Highcharts 工具提示制作新的工具提示,并在鼠标悬停时显示它并有一些超时:

load: function() {
  chart = this;
  this.myTooltip = new Highcharts.Tooltip(this, this.options.tooltip);
  this.tooltip.label.element.remove();
}


    point: {
      events: {
        mouseOver: function(e) {
          var i = this.x;
          points = [];
          Highcharts.each(this.series.chart.series, function(s) {
            Highcharts.each(s.data, function(p) {
              if (p.x === i) {
                points.push(p)
              }
            })
          });
          myTooltip = chart.myTooltip;
          setTimeout(function() {
            myTooltip.refresh(points, e)
          }, 1000)

        }, mouseOut: function() {
        setTimeout(function() {
        chart.myTooltip.hide();
          }, 1000)
        }
      }
    }

在这里你可以看到一个例子:http://jsfiddle.net/az39das8/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多