当followPointer标志打开时,Highcharts Tooltip显示箭头/插入符号

时间:2018-05-03 17:58:54

标签: javascript highcharts tooltip

我试图让Highcharts笛卡尔图表显示我的工具提示上的插入符号/箭头,尽管followPointer已打开。

阅读文档,显示插入符号的一种方法是关闭followPointer。但是,对于我的用途,如果我能在所有情况下都能使用它,那将是理想的。

我尝试检查工具提示here的源代码以查看followPointer代码是如何实现的,也许它会告诉我一下是否有一个标志可以打开或关闭箭头,但似乎我无法找到任何类似的东西。

如果您需要,可以随意使用:http://jsfiddle.net/Malinga/oo2njkhs/2/

1 个答案:

答案 0 :(得分:0)

我找到了答案here

您基本上需要覆盖在Highcharts中实现的move方法,将skipAnchor设置为false

(function(H) {
  H.wrap(H.Tooltip.prototype, 'move', function(proceed, x, y, anchorX, anchorY) {
    var tooltip = this,
      now = tooltip.now,
      animate = tooltip.options.animation !== false && !tooltip.isHidden &&
      // When we get close to the target position, abort animation and land on the right place (#3056)
      (Math.abs(x - now.x) > 1 || Math.abs(y - now.y) > 1),
      skipAnchor = tooltip.followPointer || tooltip.len > 1;

    skipAnchor = false;

    // Get intermediate values for animation
    H.extend(now, {
      x: animate ? (2 * now.x + x) / 3 : x,
      y: animate ? (now.y + y) / 2 : y,
      anchorX: skipAnchor ? undefined : animate ? (2 * now.anchorX + anchorX) / 3 : anchorX,
      anchorY: skipAnchor ? undefined : animate ? (now.anchorY + anchorY) / 2 : anchorY
    });

    // Move to the intermediate value
    tooltip.getLabel().attr(now);


    // Run on next tick of the mouse tracker
    if (animate) {

      // Never allow two timeouts
      clearTimeout(this.tooltipTimeout);

      // Set the fixed interval ticking for the smooth tooltip
      this.tooltipTimeout = setTimeout(function() {
        // The interval function may still be running during destroy,
        // so check that the chart is really there before calling.
        if (tooltip) {
          tooltip.move(x, y, anchorX, anchorY);
        }
      }, 32);

    }
  });
}(Highcharts));