首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >高级图表chart.tooltip.formatter覆盖series.tooltip.pointFormatter?

高级图表chart.tooltip.formatter覆盖series.tooltip.pointFormatter?
EN

Stack Overflow用户
提问于 2017-04-13 09:38:50
回答 2查看 11.4K关注 0票数 5

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

代码语言:javascript
复制
Highcharts.chart('container', {
    tooltip: {
            formatter: function () { return 'Default Format ...';  }
    },
    ...
}

..。对于某些系列,我需要指定一个修改的格式化程序:

代码语言:javascript
复制
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...'; }
    }
  }, 
  ...
]

因此,这是行不通的,因为,正如我所理解的,图表工具提示格式化程序总是覆盖系列配置的pointFormatter。您可以尝试此这里,如果您注释掉图表工具提示配置。

我希望有一种方法来为整个图表设置对格式化程序函数的“默认”工具提示配置,以及为某些系列设置重写此配置的可能性。是否有办法这样做?

我找到了一些类似于的方法,但我需要比格式化程序函数中的if-elseing系列名称更一般的分配。我也希望能够修改值,所以像'valueSuffix‘这样的属性不会让我走得太远。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-13 11:19:29

我不太清楚这种覆盖是如何发生的,但是正如您提到的,tooltip.formatter优先。不要使用tooltip.formatter,而是将相同的函数移动到plotOptions.series.tooltip.pointFormatter。这应该如您所期望的那样工作,通常使用plotOptions pointFormatter,在特定情况下使用series pointFormatter

例如(JSFiddle):

代码语言:javascript
复制
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...'; }
    }
}]
票数 8
EN

Stack Overflow用户

发布于 2019-12-18 15:49:39

为了避免覆盖,您需要对图表工具提示使用选项headerFormat,并为各个系列定义点格式。

https://api.highcharts.com/highcharts/tooltip.headerFormat

语法有点不同,但至少它提供了基本的格式化选项。

假设您想要自定义日期格式和操作字体大小和颜色,

您的代码应该如下所示:

代码语言:javascript
复制
Highcharts.chart('container', {
    tooltip: {
        valueSuffix: '',
        xDateFormat: '%a, %b %e at %l:%M %p',
        headerFormat: '<span style="font-size: 14px; font-weight: 500; color: #8995a0;">{point.key}</span>',
    },
    ...
}

..。对于某些系列,指定修改后的格式化程序:

代码语言:javascript
复制
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...'; }
    }
  }, 
  ...
]
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43388706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档