更新答案
在格式化程序回调中,您可以在 span 内包装文本并正确设置样式。
formatter: function () {
var color = this.y === this.point.high ? 'red' : 'blue';
return '<span style="color:' + color + '">' + this.y + '°C</span>';
}
示例:http://jsfiddle.net/6ofbr32b/1/
为点片段着色
您必须将一个点分成两点 - 这将代表其负值和正值,将阈值设置为 0 和negativeColor。然后调整工具提示和数据标签。
这样就可以实现分割;
//plotOptions.columnRange
negativeColor: 'red',
threshold: 0,
borderWidth: 0,
//series
keys: ['x', 'low', 'high', 'part'],
data: [
[0,-9.7, 0, 'neg'],
[0,0,9.4, 'pos'],
[1,-8.7, 0, 'neg'],
[1, 0, 6.5, 'pos'],
[2,-3.5, 0, 'neg'],
[2, 0, 9.4, 'pos'],
[3,0.0, 22.6],
[4,2.9, 29.5],
]
'part' 是一个帮助器,可用于调整工具提示和数据标签。
数据标签,因此如果点被分割,将只显示一条边
dataLabels: {
enabled: true,
formatter: function() {
if (this.point.part === 'neg' && this.y === this.point.low) {
return this.y + '°C';
} else if (this.point.part === 'pos' && this.point.high === this.y) {
return this.y + '°C';
} else if (!this.point.part) {
return this.y + '°C';
}
return '';
}
}
和工具提示
tooltip: {
pointFormatter: function () {
var points = this.series.points,
low = this.low,
high = this.high;
if (this.part === 'neg') {
low = this.low;
high = points[this.index + 1].high;
} else if (this.part === 'pos') {
low = points[this.index - 1].low;
high = this.high;
}
return '<span style="color:' + this.series.color + '">\u25CF</span> ' + this.series.name + ': <b>' + low + '°C</b> - <b>' + high + '°C</b><br/>';
}
},
示例:http://jsfiddle.net/xdg67kuo/3/
用堆积柱形图也可以达到想要的效果:
example