高图:通过系列名称设置单独的文本颜色

时间:2019-12-04 14:36:01

标签: javascript charts highcharts

我需要使用Highcarts在“绘图选项”>“系列”>“颜色”中设置单独的颜色。 我尝试使用this.series.name来获取系列名称,并按名称设置颜色,但是我不能,我总是得到“未定义”

this.chartYear = new Chart({
      chart: {
        type: 'column'
      },
      title: {
        text: ''
      },
      xAxis: {
        categories: this.yearData.months
      },
      yAxis: {
        min: 0,
        stackLabels: {
          enabled: false,
        },
        title: {
          text: null
        }
      },
      plotOptions: {
        column: {
          stacking: 'normal',
          dataLabels: {
            enabled: true
          },
          pointWidth: this.innerHeight > 800 ? 60 : 40
        },
        series: {
          dataLabels: {
            enabled: true,
            color: I NEEDED SET INDIVIDUAL COLOR HERE,
            style: {
              textOutline: 'false',
              fontFamily: 'Segoe UI, Robot, Helvetica Neue, Arial, sans-serif',
              fontWeight: '400',
              color: "#212529",
              fontSize: '12px'
            }
          },
          showInLegend: false
        }
      },
      series: series,
      exporting: {
        enabled: false
      }
    })

1 个答案:

答案 0 :(得分:0)

您可以在系列级别上为数据标签定义颜色:

series: [{
    dataLabels: {
        color: 'red'
    },
    ...
}, {
    dataLabels: {
        color: 'yellow'
    },
    ...
}]

实时演示: http://jsfiddle.net/BlackLabel/cv740ygL/

API参考: https://api.highcharts.com/highcharts/series.column.dataLabels