Javascript Highcharts chart.tooltip.formatter覆盖系列.tooltip.pointFormatter?

Javascript Highcharts chart.tooltip.formatter覆盖系列.tooltip.pointFormatter?,javascript,highcharts,Javascript,Highcharts,我的方法是使用特定的工具提示格式配置图表: Highcharts.chart('container', { tooltip: { formatter: function () { return 'Default Format ...'; } }, ... } 。。。对于某些系列,我需要指定一个modyfied格式化程序: series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0,

我的方法是使用特定的工具提示格式配置图表:

Highcharts.chart('container', {
    tooltip: {
            formatter: function () { return 'Default Format ...';  }
    },
    ...
}
。。。对于某些系列,我需要指定一个modyfied格式化程序:

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...'; }
    }
  }, 
  ...
]
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...'; }
    }
  }, 
  ...
]
所以这不起作用,因为,正如我所理解的,图表工具提示格式化程序总是覆盖系列配置的pointFormatter。如果注释掉图表工具提示配置,可以尝试此操作

我希望有一种方法可以在整个图表的格式化程序函数上设置“默认”工具提示配置,并有可能覆盖某些系列的工具提示配置。有没有办法做到这一点


我发现了一些类似的方法,但我需要一种比在格式化程序函数中使用序列名更通用的方法。我还希望能够修改值,因此像“valueSuffix”这样的属性不会让我走得太远。

我不太确定这种重写是如何发生的,但正如您提到的
工具提示。格式化程序优先。不要使用
tooltip.formatter
而是将相同的函数移动到
plotOptions.series.tooltip.pointFormatter
。这应该如您所期望的那样工作,一般使用
绘图选项
点格式设置程序
,在特定情况下使用您的
系列
点格式设置程序

例如():

plotOptions:{
系列:{
工具提示:{
pointFormatter:function(){return'Default'+this.x+'是'+this.y+'';}
}
}
},
系列:[{
数据:[29.9,71.5,106.4,129.2,144.0,176.0,135.6148.5,216.4194.1,95.6,54.4],
工具提示:{
pointFormatter:函数(){return'自定义格式…';}
}
}]

为避免覆盖,需要在图表工具提示中使用选项headerFormat,并为各个系列定义点格式

语法有点不同,但至少它提供了基本的格式化选项

假设您想要自定义日期格式并操纵字体大小和颜色

您的代码应该如下所示:

Highcharts.chart('container', {
    tooltip: {
        valueSuffix: '',
        xDateFormat: '%a, %b %e at %l:%M %p',
        headerFormat: '<span style="font-size: 14px; font-weight: 500; color: #8995a0;">{point.key}</span>',
    },
    ...
}
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...'; }
    }
  }, 
  ...
]