在 Highcharts 中将 CSS 添加到特定系列的图例标签

Posted

技术标签:

【中文标题】在 Highcharts 中将 CSS 添加到特定系列的图例标签【英文标题】:Add CSS to a specific series' legend label in Highcharts 【发布时间】:2017-08-09 03:18:19 【问题描述】:

我有一个包含两个系列的 Highcharts 图表。我想将一些 css 应用于单个系列的图例标签,而保持其他系列的图例标签不变。

显然,这可以通过一些复杂的选择器或其他东西来实现,但是我可以在 Highcharts 配置对象中放入一些优雅的东西来实现这一点吗?

【问题讨论】:

【参考方案1】:

以下是如何使用格式化程序将自定义类添加到标签的示例:

var options = 
  xAxis: 
    labels: 
        enabled: true,
      usehtml: true,
      formatter () 
        return this.isFirst ? `<span class="myclass">$this.value</span>` : this.value
      
    
  ,
  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],
    type: 'column'
  ]


var chart = Highcharts.chart('container', options)

现场示例: https://jsfiddle.net/4vpskrgw/

问候。

【讨论】:

以上是关于在 Highcharts 中将 CSS 添加到特定系列的图例标签的主要内容,如果未能解决你的问题,请参考以下文章