我的方法是使用特定的工具提示格式配置图表:
Highcharts.chart('container', {
tooltip: {
formatter: function () { return 'Default Format ...'; }
},
...
}
...对于某些系列,我需要指定一个经过修改的格式化程序:
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
tooltip: {
pointFormatter: function () { return 'Custom Format...'; }
}
},
...
]
所以这是行不通的,因为正如我发现的那样,chart-tooltip-formatter 总是覆盖系列配置的 pointFormatter。你可以试试这个 here ,如果您注释掉图表工具提示配置。
我希望有一种方法可以为整个图表的格式化程序功能设置“默认”工具提示配置,并有可能为某些系列覆盖它。有办法吗?
我发现了一些方法,例如 this ,但我需要一个比格式化程序函数中的 if-elseing 系列名称更通用的方法。我还希望能够修改值,所以像“valueSuffix”这样的属性不会让我走得太远。
最佳答案
我不太确定这种覆盖是如何发生的,但是正如您提到的那样,tooltip.formatter
优先。不使用 tooltip.formatter
,而是将相同的函数移动到 plotOptions.series.tooltip.pointFormatter
。这应该按您预期的那样工作,一般使用 plotOptions
pointFormatter
而您的 series
pointFormatter
用于具体情况。
例如(JSFiddle):
plotOptions: {
series: {
tooltip: {
pointFormatter: function () { return 'Default ' + this.x + '</b> is <b>' + this.y + '</b>'; }
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
tooltip: {
pointFormatter: function () { return 'Custom Format...'; }
}
}]
关于javascript - Highcharts chart.tooltip.formatter 覆盖 series.tooltip.pointFormatter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43388706/