【发布时间】:2016-09-02 08:33:43
【问题描述】:
我遇到了 HighCharts 问题,更具体地说是列范围图。我想为 负 数字设置 红色,为 正 数字设置 蓝色。
当前代码将 red 颜色赋予具有 Only positive 值的条形,并将 blue 颜色赋予区间包含 负 值的那些:
$(function () {
$('#container').highcharts({
chart: {
type: 'columnrange',
inverted: false
},
title: {
text: 'Temperature variation by month'
},
subtitle: {
text: 'Observed in Vik i Sogn, Norway'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature ( °C )'
}
},
tooltip: {
valueSuffix: '°C'
},
plotOptions: {
columnrange: {
dataLabels: {
enabled: true,
grouping:true,
formatter: function () {
if(this.y == 0)
return "";
else
return this.y;
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Temperatures',
color: '#FF0000',
displayNegative: true,
negativeColor: '#0088FF' ,
data: [
[0, 9.4],
[-8.7, 6.5],
[-3.5, 9.4],
[-1.4, 19.9],
[0.0, 22.6],
[2.9, 29.5],
[9.2, 30.7],
[7.3, 26.5],
[4.4, 18.0],
[-3.1, 11.4],
[-5.2, 10.4],
[-13.5, 9.8]
]
}]
});
});
需要的结果应该是这样的:
【问题讨论】:
-
此时,Highcharts 允许您根据参数设置阈值和色点。示例:jsfiddle.net/s3c82p6w。在负部分应该着色的情况下,您需要将每个(负/正点)拆分为点。示例:jsfiddle.net/xdg67kuo
-
看看这个column chart with split colors。低于阈值的数字的颜色范围
标签: javascript highcharts