gpt4 book ai didi

javascript - Highcharts:在工具提示中格式化系列名称

转载 作者:行者123 更新时间:2023-11-30 07:57:17 25 4
gpt4 key购买 nike

我在同一个图表上有多个系列,我想使用工具提示格式化程序使系列名称在工具提示中看起来可读。目前,它们以 SeriesonenameSeriestwoname 的形式显示,但我希望它们以 Series One Name 的形式显示> 和 第二系列名称。我仍然希望工具提示的格式与 Series One Name: 0.567 相同。

我在格式化图表标签时做了类似的事情,我在其中使用了以下代码:

legend: {
labelFormatter: function () {
return {
'Seriesonename': 'Series One Name',
'Seriestwoname': 'Series Two Name'
}[this.name];
}
}

我试过对工具提示格式化程序做同样的事情,但我似乎无法让它工作。我怀疑这与它是共享工具提示这一事实有关,但我不是 100% 确定。

如有任何帮助,我们将不胜感激!

最佳答案

要对工具提示的 legend.labelFormatter 执行类似的方法,您可以使用 tooltip.formattertooltip.pointFormatter,具体取决于关于图表的设置方式。

使用 tooltip.pointFormatter 的示例可以是 ( JSFiddle ):

tooltip: {
pointFormatter: function() {
var seriesNameConverter = {
'Seriesonename': 'Series One Name',
'Seriestwoname': 'Series Two Name'
};

return '<span style="color:{point.color}">\u25CF</span> '
+ seriesNameConverter[this.series.name] + ': <b>' + this.y + '</b><br/>';
}
}

这是 tooltip.pointFormat 的默认样式,用您的转换代替系列名称。

关于javascript - Highcharts:在工具提示中格式化系列名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36837834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com