英文:
Is there a possibility to simultaneously show the tooltips for all the data points in the series on hover of one any points?
问题
Highcharts.js是否有选项可以在悬停在系列中的任何数据点上时显示所有数据点的工具提示?
我已经找到了许多解决方案,并成功重现了在同一点上显示多个系列的情况,但没有找到类似这样的解决方案。
谢谢!
英文:
Is there an option to setup Highcharts.js to show the tooltips for all the data points in the series on hover of any of the data point in that series?
E.g. something like this when green bar is hovered over:
I've found many solutions and managed to reproduce for showing multiple series on the same point, but nothing like this.
Thanks!
答案1
得分: 1
以下是翻译好的部分:
没有针对这种工具提示的内置功能,但您可以相对容易地创建它。只需使用Highcharts.SVGRenderer
类,添加自定义标签,并在mouseOver
/ mouseOut
系列事件上显示/隐藏它们。默认工具提示在幕后使用非常相似的方法。
例如:
tooltip: {
enabled: false
},
plotOptions: {
column: {
events: {
mouseOver: function() {
const chart = this.chart;
const points = this.points;
points.forEach(point => {
let customTooltip = point.customTooltip;
const text = `<span style="color:${this.color}">●</span> <span style="font-size: 0.8em">${this.name}</span><br/>x: ${point.x}, y: ${point.y}`;
const anchorX = point.tooltipPos[0] + chart.plotLeft;
const anchorY = point.tooltipPos[1] + chart.plotTop;
if (!customTooltip) {
customTooltip = point.customTooltip = chart.renderer
.label(text, anchorX, anchorY - 100, 'callout')
.attr({
align: 'center',
zIndex: 8,
stroke: point.color,
fill: 'rgba(155, 155, 155, 0.75)',
padding: 8,
r: 5
}).add();
} else {
customTooltip.show();
}
customTooltip.attr({
anchorX,
anchorY,
x: anchorX,
y: anchorY - customTooltip.height - 8
});
});
},
mouseOut: function() {
this.points.forEach(point => {
point.customTooltip.hide();
});
}
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/h6ys735b/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#label
英文:
There is no built-in functionality for such tooltips, but you can relatively easily create it. It is enough to use the Highcharts.SVGRenderer
class, add custom labels and show/hide them on mouseOver
/ mouseOut
series events. The default tooltip uses really similar approach under the hood.
For example:
tooltip: {
enabled: false
},
plotOptions: {
column: {
events: {
mouseOver: function() {
const chart = this.chart;
const points = this.points;
points.forEach(point => {
let customTooltip = point.customTooltip;
const text = `<span style="color:${this.color}">●</span> <span style="font-size: 0.8em">${this.name}</span><br/>x: ${point.x}, y: ${point.y}`;
const anchorX = point.tooltipPos[0] + chart.plotLeft;
const anchorY = point.tooltipPos[1] + chart.plotTop;
if (!customTooltip) {
customTooltip = point.customTooltip = chart.renderer
.label(text, anchorX, anchorY - 100, 'callout')
.attr({
align: 'center',
zIndex: 8,
stroke: point.color,
fill: 'rgba(155, 155, 155, 0.75)',
padding: 8,
r: 5
}).add();
} else {
customTooltip.show();
}
customTooltip.attr({
anchorX,
anchorY,
x: anchorX,
y: anchorY - customTooltip.height - 8
});
});
},
mouseOut: function() {
this.points.forEach(point => {
point.customTooltip.hide();
});
}
}
}
}
Live demo: http://jsfiddle.net/BlackLabel/h6ys735b/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#label
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论