如何将自定义渲染器文本的颜色更改为 Highcharts 中的标题颜色

How to change the color of a custom renderer text to the title color in Highcharts

我有以下图表:

var chart = Highcharts.chart('chartcontainer', {
  chart: {
    polar: true,
    type: 'column'
  }, 
  [other code]
       }, function (chart) {
         chart.renderer.text(textLine, 40, 80).css({'red'}).add();
       });

renderer.text() 函数为我提供了可轻松修改的自定义文本。但是,此图用于更复杂的情况,上下文将决定文本的颜色(因此它不固定为 'red')。我需要给它标题的颜色。标题颜色通过其他地方的选项设置。

一切正常,但我似乎无法获取该颜色值并将其正确分配给文本颜色值,如下所示:

chart.customText.style.color = chart.title.style.color;

如何做到这一点?

您可以通过以下方式获取颜色:chart.title.styles.color。示例:

var chart = Highcharts.chart('container', {
    ...
}, function(chart) {
    chart.renderer.text('Some text', 40, 80).css({
        color: chart.title.styles.color
    }).add();
});

现场演示: http://jsfiddle.net/BlackLabel/10u2nLay/