首页 文章

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

提问于
浏览
1

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

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

In HighCharts Controller

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上时发生鼠标悬停事件,以便将更多信息发送到工具提示中:

In 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) {
                ....

1 回答

  • 0
    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 .

相关问题