我有3个停靠点,分别为0.4、0.6和0.8(红色,绿色,蓝色)。最大值为100(百分比)
如果我将数据设置为50,我希望它是绿色,但似乎是绿色和红色的混合。只有当我达到60时,它才是我期望的亮绿色。
是否要删除渐变?
https://jsfiddle.net/sy3r2hj7/1/
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.40, '#ff0000'],
[0.60, '#00ff00'], // yellow
[0.80, '#0000ff'] // red
],
lineWidth: 0,
minorTickInterval: null,
tickAmount: 2,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Speed'
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [60],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">km/h</span></div>'
},
tooltip: {
valueSuffix: ' km/h'
}
}]
}));
答案 0 :(得分:1)
您可以根据某些条件,以编程方式更改点的颜色,而不是使用stops
属性:
events: {
render: function() {
var point = this.series[0].points[0];
if (point.y < 40) {
point.graphic.attr({
fill: '#ff0000'
})
} else if (point.y < 60) {
point.graphic.attr({
fill: '#00ff00'
})
} else {
point.graphic.attr({
fill: '#0000ff'
})
}
}
}