highcharts - 如何在 Highcharts 上制作 3 种不同的颜色
问题描述
我在我的项目中使用 highcharts,现在我只能制作 2 种不同的颜色。当值 >= 0 时为蓝色,为负数时为红色。
有没有办法把它变成3种颜色?因此,当值 = 0 时,颜色变为绿色,我尝试使用那里有人演示的“linkedTo”,但我的数据 [] 是动态的。
$(function () {
$('#jugernaut<?php echo $a; ?>').highcharts({
chart: {
type: 'column',
spacing:[0,0,0,0],
height: 450
},
title: {
text: '<?php echo $key->carline.' '.$key->conveyeor ?>',
style: {
fontSize: '18px',
fontFamily: 'Verdana, sans-serif'
}
},
yAxis:
{ visible: false,
tickLength:1,
title: {
text: ''
},
labels: {
style: {
fontSize: '17px',
fontWeight: 'bold'
},
plotLines: [{
color: '#C0C0C0',
width: 5,
value: 0
}]
},
},
xAxis:{
tickInterval:1,
labels: {
style: {
fontSize: '17px',
fontWeight: 'bold'
},
}
},
credits: {
text: '',
enable:false,
},
plotOptions:{
marker:{
enabled: false
}
},
series: [
{
name: ' ',
type: 'spline',
data: <?php echo json_encode(${"jamnya".$i});?>,
color: '#1122DD',
threshold: 0,
negativeColor: 'red',
}
]
});
});
*对不起,如果我的英语这么差
解决方案
对的,这是可能的。例如,您可以使用zones
功能来定义三个级别的值的颜色。这是示例代码:
series: [{
data: [-10, -5, 0, 5, 10, 15, 10, 10, 5, 0, -5],
zones: [{
value: 0,
color: 'red'
}, {
value: 0.000001,
color: 'green'
}, {
color: 'blue'
}]
}]
此外,您可以通过color: 'green'
直接向该0
点添加属性来实现这一点,就像这样:
series: [{
data: [-10, -5, {y:0, color: 'green'}, 5, 10, 15, 10, 10, 5, {y:0, color: 'green'}, -5],
zones: [{
value: 0,
color: 'red'
}, {
color: 'blue'
}]
}]
以下是示例:
API参考:
https://api.highcharts.com/highcharts/plotOptions.line.zones
推荐阅读
- java - 我怎样才能让这个 ActionListener 工作?
- java - “中断”和“返回”之间的区别
- javascript - 优化 Firebase 请求
- javascript - 动态生成的按钮无法通过 jQuery
- c++ - 难以理解 C++ 上的 Do-While 循环
- python - 请求库上的 Python 3 状态
- python - 我想返回两个值,但只打印一个
- html - 如何使用 HTML 和 CSS 在图像上添加文本覆盖
- next.js - Next.js 图像组件不显示 Cloudinary 图像
- javascript - 点击确认 HTML 不适用于 Sweetalert2,但它适用于本机浏览器确认