Loc*_*rst 5 javascript highcharts
我的方法是使用某种工具提示格式配置图表:
Highcharts.chart('container', {
tooltip: {
formatter: function () { return 'Default Format ...'; }
},
...
}
Run Code Online (Sandbox Code Playgroud)
...对于某些系列,我需要指定一个修改过的格式化程序:
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...'; }
}
},
...
]
Run Code Online (Sandbox Code Playgroud)
所以这不起作用,因为,正如我发现的那样,图表工具提示格式化程序总是覆盖系列配置的 pointFormatter。如果您注释掉图表工具提示配置,您可以在此处尝试。
我希望有一种方法可以在整个图表的格式化程序功能上设置“默认”工具提示配置,并且可以为某些系列覆盖它。有没有办法这样做?
我发现像一些方法这个,但我需要比格式化函数内如果-elseing系列名称的更一般的apporach。我也希望能够修改值,所以像“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...'; }
}
}]
Run Code Online (Sandbox Code Playgroud)