【发布时间】:2015-01-14 02:07:29
【问题描述】:
为什么在这个脚本中标签颜色仍然是黑色的?
plotOptions: {
series: {
dataLabels: {
enabled: true,
color: ['#7cb5ec', '#434348'],
}
}
}
【问题讨论】:
标签: javascript colors highcharts label
为什么在这个脚本中标签颜色仍然是黑色的?
plotOptions: {
series: {
dataLabels: {
enabled: true,
color: ['#7cb5ec', '#434348'],
}
}
}
【问题讨论】:
标签: javascript colors highcharts label
颜色属性只接受一种颜色——如果你想对不同的系列应用不同的颜色,你必须编写自己的“格式化程序”函数:
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function () {
return '<span style="color:' + (this.series.name == "series1" ? '#7cb5ec' : '#434348' ) + '">' + this.y + '</span>';
}
}
}
},
为您的系列提供一个名称,并通过名称进行区分,以便为标签提供正确的颜色。
有关工作演示,请参见此处:http://jsfiddle.net/oa2dgwku/
【讨论】: