Highcharts solidgauge的默认工具提示位置

时间:2019-09-10 05:01:21

标签: javascript highcharts

https://jsfiddle.net/7cbymps6/

    tooltip: {
        positioner: function () {
            if(true) {
                return { 
                    x: this.chart.plotWidth / 1.5,
                    y: this.chart.plotHeight / 2
                };
            } else {
                return {
                  /*x: defaultX ??,
                    y: defaultY ?? */
                };
            }
        }       
    },

在else语句中,我想按原样放置工具提示位置。但是,如果没有return语句,则会产生错误。如果我返回一个空对象,这一次会将工具提示放在图表的左上角。我如何返回以前的x和y值?谢谢

1 个答案:

答案 0 :(得分:1)

您必须使用回调属性pointlabelWidthlabelHeight这样来计算默认位置:

  tooltip: {
    positioner: function(labelWidth, labelHeight, point) {
      if (false) {
        return {
          x: this.chart.plotWidth / 1.5,
          y: this.chart.plotHeight / 2
        };
      } else {
        return {
          x: point.plotX + this.chart.plotLeft - labelWidth / 2,
          y: point.plotY + this.chart.plotTop - labelHeight - 10
        };
      }
    }
  }

演示: