我有一个包含多个系列和共享工具提示的柱形图。 positioner(labelWidth, labelHeight, point)
回调函数中的点对象仅包含悬停类别中的最左侧点。我想将工具提示放在该类别中最高栏的上方。如果最左边的条小于任何其他条,则工具提示将覆盖这些较高的条。
有没有什么方法可以获得悬停类别中的所有点而不是最左边的点?
答案 0 :(得分:2)
您可以循环hoverPoints
并找到您需要的那个。
positioner: function(w, h) {
var chart = this.chart,
hoverPoints = chart.hoverPoints,
len = hoverPoints.length,
topPoint = hoverPoints[0],
x,
y;
for (var i = 0; i < len; i++) {
if (hoverPoints[i].y > topPoint.y) {
topPoint = hoverPoints[i];
}
}
x = topPoint.barX + chart.plotLeft + topPoint.pointWidth / 2 - w / 2;
y = topPoint.plotY + chart.plotTop - h;
return {
x: x,
y: y
};
},