我在同一个图表上有多个系列,我想使用工具提示格式化程序使系列名称在工具提示中看起来是可读的。目前,它们以Seriesonename和Seriestwoname的形式显示,但我希望它们以Series One Name和Series Two Name的形式显示。我仍然希望将工具提示保持在相同的Series One Name: 0.567格式中。
在格式化图表标签时,我做了类似的事情,我使用了以下代码:
legend: {
labelFormatter: function () {
return {
'Seriesonename': 'Series One Name',
'Seriestwoname': 'Series Two Name'
}[this.name];
}
}我尝试过对工具提示格式化程序做同样的工作,但我似乎无法让它开始工作。我怀疑这与这是一个共享的工具提示有关,但我不能百分之百肯定。
任何帮助都将不胜感激!
发布于 2016-04-25 11:26:48
要对工具提示执行类似的legend.labelFormatter方法,您可以使用tooltip.formatter或tooltip.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的默认样式,您的转换将取代系列名称。
https://stackoverflow.com/questions/36837834
复制相似问题