如何从配置对象外部调用 Highcharts 工具提示格式化程序函数?

How to call Highcharts tooltip formatter function from outside the config object?

所以我有一个有趣的问题。

这里是格式化程序函数在图表配置对象中的位置:

在 HighCharts 控制器中

vm.config = {
    options: {
        ....
        chart: {
            ....
        },
        navigator: {
            ....
        },
        tooltip: {
            shared: true,
            useHTML: true,
            backgroundColor: null,
            borderWidth: 0,
            shadow: false,
            formatter: function(tooltipObj) {
                return formatTooltip(tooltipObj, this.points);
            }
        },
        ....

我希望能够从我应用程序的另一个地方调用 formatTooltip 函数。但是,1)我该怎么做?和 2) 如何传入 tooltipObj?

例如,在我的 alertFactory 内部,我希望当用户将鼠标悬停在 plotBand 上时发生鼠标悬停事件,以将更多信息发送到工具提示中:

在 AlertsFactory

var formatPlotBand = _.curry((color, alert) => {
    return {
        color : color,
        from  : alert.start_epoch * 1000,
        to    : alert.end_epoch * 1000,
        id    :'alert-plotband',
        events: {
            mouseover: function (e) {
                /*
                    Somehow from here call the formatTooltip function
                    in the highCharts Controller.
                */
            },
            mouseout: function (e) {
                ....
var formatPlotBand = _.curry((color, alert) => {
return {
    color : color,
    from  : alert.start_epoch * 1000,
    to    : alert.end_epoch * 1000,
    id    :'alert-plotband',
    events: {
        mouseover: function (e) {
            vm.config.options.tooltip.formatter(tooltipObj);
            chart.tooltip.refresh([chart.series[0].points[i]])
        },
        mouseout: function (e) {
            ....

我不知道 vm 是否是您对图表的称呼,因此请将代码中的 chart 替换为您使用的任何变量名称。