Is there a possibility to simultaneously show the tooltips for all the data points in the series on hover of one any points?

huangapple go评论77阅读模式
英文:

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 a possibility to simultaneously show the tooltips for all the data points in the series on hover of one any points?

我已经找到了许多解决方案,并成功重现了在同一点上显示多个系列的情况,但没有找到类似这样的解决方案。

谢谢!

英文:

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:
Is there a possibility to simultaneously show the tooltips for all the data points in the series on hover of one any points?

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 =&gt; {
let customTooltip = point.customTooltip;
const text = `&lt;span style=&quot;color:${this.color}&quot;&gt;●&lt;/span&gt; &lt;span style=&quot;font-size: 0.8em&quot;&gt;${this.name}&lt;/span&gt;&lt;br/&gt;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, &#39;callout&#39;)
.attr({
align: &#39;center&#39;,
zIndex: 8,
stroke: point.color,
fill: &#39;rgba(155, 155, 155, 0.75)&#39;,
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 =&gt; {
point.customTooltip.hide();
});
}
}
}
}

Live demo: http://jsfiddle.net/BlackLabel/h6ys735b/

API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#label

huangapple
  • 本文由 发表于 2023年5月11日 17:21:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定