简体   繁体   中英

Add CSS to a specific series' legend label in Highcharts

I have a Highcharts chart with two series. I would like to apply some css to a single series' legend label, leaving the other series' legend label untouched.

Clearly this is possible with some complicated selectors or something, but is there something elegant I can put in the Highcharts config object to make this happen?

Here is a example of how you can add custom class to your label using formatter:

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)

Live example: https://jsfiddle.net/4vpskrgw/

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM