如何在高图表中更改标签颜色

How to change label colors in Highcharts

本文关键字:标签 颜色 高图表      更新时间:2023-09-26

为什么在这个脚本中标签颜色仍然是黑色的?

plotOptions: {
  series: {
    dataLabels: {
      enabled: true,
      color: ['#7cb5ec', '#434348'],
    }
  }
}

color-属性只接受一种颜色 - 如果您希望将不同的颜色应用于不同的系列,则必须编写自己的"格式化程序"函数:

plotOptions: {
            series: {
                dataLabels: {
                    enabled: true,
                    formatter: function () {
                        return '<span style="color:' + (this.series.name == "series1" ? '#7cb5ec' : '#434348' ) + '">' + this.y + '</span>';
                    }
                }
            }
        },

为您的系列提供名称,并通过名称进行区分,以便为标签提供正确的颜色。

有关工作演示,请参见此处:http://jsfiddle.net/oa2dgwku/