javascript - Highcharts chart.tooltip.formatter 覆盖 series.tooltip.pointFormatter?

标签 javascript highcharts

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

Highcharts.chart('container', {
    tooltip: {
            formatter: function () { return 'Default 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...'; }
    }
  }, 
  ...
]

所以这是行不通的,因为正如我发现的那样,chart-tooltip-formatter 总是覆盖系列配置的 pointFormatter。你可以试试这个 here ,如果您注释掉图表工具提示配置。

我希望有一种方法可以为整个图表的格式化程序功能设置“默认”工具提示配置,并有可能为某些系列覆盖它。有办法吗?

我发现了一些方法,例如 this ,但我需要一个比格式化程序函数中的 if-elseing 系列名称更通用的方法。我还希望能够修改值,所以像“valueSuffix”这样的属性不会让我走得太远。

最佳答案

我不太确定这种覆盖是如何发生的,但是正如您提到的那样,tooltip.formatter 优先。不使用 tooltip.formatter,而是将相同的函数移动到 plotOptions.series.tooltip.pointFormatter。这应该按您预期的那样工作,一般使用 plotOptions pointFormatter 而您的 series pointFormatter 用于具体情况。

例如(JSFiddle):

plotOptions: {
    series: {
        tooltip: {
            pointFormatter: function () { return 'Default ' + this.x + '</b> is <b>' + this.y + '</b>';  }
        }
    }
},

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...'; }
    }
}]

关于javascript - Highcharts chart.tooltip.formatter 覆盖 series.tooltip.pointFormatter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43388706/

相关文章:

javascript - 如何将 praat 脚本合并到网页/数据库中

javascript - Python-Requests,如何动态接收url?

javascript - 允许select2 jquery ajax在标签模式下重复标签

highcharts - 如何制作 Highchart 2 或更多内馅饼,但只有 1 个外馅饼带有 donut 类型?

highcharts - 如何将 highcharts 折线图点颜色设置为颜色数组?

javascript - 基于URL查询的后台切换

javascript - 让第一个 child 打开 Accordion

jquery - 隐藏除选定数据系列之外的所有数据系列、HighCharts

image - 更改按钮图像

javascript - 在 Highcharts 中重置 xAxis[0] 和 xAxis[1] 宽度