Highcharts - 样式模式下的工具提示宽度

Highcharts - Tooltip width in styled mode

我正在尝试在样式模式中设置动态工具提示宽度。

我正在尝试编写一个 Tooltip 包装器,但无法弄清楚我应该包装哪个函数,有人可以建议一下吗?

下面是方法示例

H.wrap(H.Tooltip.prototype, 'theFunc', (p) => {
  const label = this.label;
    const width = this.chart.plotWidth < 300 ? 100 : 200;
    label.css({width: width+'px'});
})

更新: 当 useHTML 设置为 true

时我得到的结果

不需要包装任何方法,使用formatter回调函数就够了:

    tooltip: {
        useHTML: true,
        formatter: function() {
            const chart = this.series.chart;
            const width = chart.plotWidth < 300 ? 100 : 200;

            return '<div style="width:' + width + 'px">' + this.y + '</div>'
        }
    }

现场演示: http://jsfiddle.net/BlackLabel/5kdonwbj/

API参考:https://api.highcharts.com/highcharts/tooltip.formatter