此文章专门用来跟踪记录vue+highCharts在使用过程中的一些常见的需求设置。本人每次开发图表的时候,看官方文档脑壳都大了,属性太多,密密麻麻的,根本记不住。所以整理一些常见的功能实现方式,方便自己今后查阅。(后续会根据实际情况不断更新)
1、隐藏右下角logo
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421151341473.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
xAxis:{...},
yAxis:{...},
credits: {
enabled: false
}
2、隐藏横线网格
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421151820624.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
yAxis:{
gridLineColor: 'transparent'
}
3、显示y轴线
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421151935528.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
yAxis:{
lineWidth: 1
}
4、自定义轴线颜色和文字颜色
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421152504776.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
xAxis:{
lineColor: 'red',
labels: {
style: {
color: 'red'
}
}
}
5、自定义线条颜色
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421153513220.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
yAxis:{...},
series: [{
data: [...],
color:'red'
}]
6、隐藏数据点marker
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421153848909.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
yAxis:{...},
series: [{
data: [...],
marker: {
enabled: false
}
}]
7、指定分区显示不同的颜色或者线条样式 官网在线例子
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210421161005388.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDE3MTc1Nw==,size_16,color_FFFFFF,t_70)
yAxis:{...},
series: [{
data: [...],
zoneAxis: 'x',
zones: [{
value: 8
}, {
dashStyle: 'dot',
color: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, 'red'],
[0.9, '#303642']
]
}
}]
}]
8、自定义图表背景颜色
chart: {
backgroundColor: '#303642',
type: 'spline'
}
9、去掉导出图表按钮
yAxis: {},
exporting: { enabled:false }
10、改变柱状图柱子颜色
![在这里插入图片描述](https://img-blog.csdnimg.cn/317d5d2969aa4790bbb857e887f8f0aa.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAU3RyaW5n5L2z5L2z,size_20,color_FFFFFF,t_70,g_se,x_16)
方法一:
plotOptions: {
series: {
colorByPoint: true,
colors: ['red', 'blue']
}
}
方法二:
xAxis: {...},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
colorByPoint: true,
colors: ['red', 'blue']
}]
11、更改数据点大小
![在这里插入图片描述](https://img-blog.csdnimg.cn/9c332ee16dd9410ebc0422988a15e842.png)
xAxis:{},
plotOptions: {
series: {
animation: false,
turboThreshold: 0,
marker: {
enabled: true,
symbol: 'circle',
radius: 10,
states: {
hover: {
enabled: true
}
}
}
}
}
12、曲线面积图
![在这里插入图片描述](https://img-blog.csdnimg.cn/d1d7510e41fd49dc807038debcdca9f7.png)
chart:{
type: 'areaspline',
marginRight: 10
},
xAxis:{},
plotOptions: {
series: {
animation: false,
turboThreshold: 0,
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, '#9CABE2'],
[1, HighCharts.Color('white').setOpacity(0).get('rgba')]
]
}
}
}
13、更改数据点颜色
![在这里插入图片描述](https://img-blog.csdnimg.cn/ea4038f6ab0c44f1a12960b0a1c46411.png)
xAxis:{},
series: [{
name: '噪声',
data: [{
x: 1637117403000,
y: 20,
marker: { fillColor: 'red' }
}]
}]
14、添加合格基准线(假设为60分)
![在这里插入图片描述](https://img-blog.csdnimg.cn/f5193db9ee3847ac87f7439a5aba69ef.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAU3RyaW5n5L2z5L2z,size_20,color_FFFFFF,t_70,g_se,x_16)
yAxis: {
plotLines: [{
color: 'red',
dashStyle: 'Dash',
width: 1,
value: 60,
zIndex: 5
}]
}
15、时间标签格式化
![在这里插入图片描述](https://img-blog.csdnimg.cn/dba42e12363e42d999fbe307ecf3ed44.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAU3RyaW5n5L2z5L2z,size_16,color_FFFFFF,t_70,g_se,x_16)
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%m月%e号'
}
}