高图:将工具提示放在条形图上的条形上方

时间:2019-01-31 15:16:19

标签: javascript highcharts

使用highcharts,我试图将条形图上的工具提示悬停在条形图的右侧上方。例如:

enter image description here

目前,我正在使用定位器功能,但似乎无法弄清楚使它起作用的数学方法。当前,当我尝试使用point.plotX和point.plotY选项时,工具提示会徘徊在似乎是随机点的位置,而我无法找到要在哪个位置获得条形图的右侧位置。这是我当前正在使用的代码

positioner: function(width, height, point) {
   return {
     x: point.plotX,
     y: point.plotY,
   };
},

这是它的外观输出:

enter image description here

2 个答案:

答案 0 :(得分:1)

positioner函数中似乎有一个错字。您应该使用由plotY属性插入的ploty

tooltip: {
    positioner: function(width, height, point) {
        return {
            x: point.plotX,
            y: point.plotY,
        }
    }
}

实时演示:http://jsfiddle.net/BlackLabel/poxv4wq1/

API参考:https://api.highcharts.com/highcharts/tooltip.positioner

编辑:

定位器功能返回相对于整个图表的工具提示坐标。值point.plotXpoint.plotY相对于绘图区域,因此您需要添加chart.plotTopchart.plotLeft值:

    positioner: function(width, height, point) {
        var columnWidth = this.chart.series[0].options.pointWidth;

        return {
            x: point.plotX + this.chart.plotLeft,
            y: point.plotY - columnWidth / 2 + this.chart.plotTop - height
        };
    }

实时演示:http://jsfiddle.net/BlackLabel/0cjftrsy/

答案 1 :(得分:0)

好吧,因为标签样式。工具提示的位置是。

这是我固定的方式。

此示例适用于http://jsfiddle.net/fqbkozpr/1/

 return {
        x: Math.max(point.plotX, width), // To the right.
        y: point.plotY + height, // Make sure to be under the line
      };