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

标签 javascript angularjs highcharts highcharts-ng

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

这是格式化程序函数位于图表配置对象内部的位置:

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

在 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 替换为您使用的任何变量名称。

关于javascript - 如何从配置对象外部调用 Highcharts 工具提示格式化程序函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38702428/

相关文章:

java - 无法使用java下载文件

highcharts - 如何将 x 轴标签放置在水平条形图的顶部

javascript - React Native 从 android res 导入音频文件

javascript - 在 for 循环中添加事件监听器

javascript - angularjs ng-重复错误: Duplicates in a repeater

javascript - 对象中的JS函数消失

javascript - 在 NodeJS 中使用 mongoose 设置值

json - Highcharts Beta 3 : Best Practice loading JSON data

javascript - $ionicHistory.goBack() 无法正常工作

javascript - RXJS 首次发出