使用场景,将空某一天的用电量,但'05:00'-'06:15'是不用电的,故不能直接将两时间端连接
(一)在两个间断点中间加如无效数据
option = {
title: {
text: '一天用电量分布',
subtext: '纯属虚构'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
toolbox: {
show: true,
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['00:00', '01:15', '02:30', '03:45', '05:00','5:10', '06:15', '07:30', '08:45', '10:00', '11:15', '12:30', '13:45', '15:00', '16:15', '17:30', '18:45', '20:00', '21:15', '22:30', '23:45']
},
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value} W'
},
axisPointer: {
snap: true
}
},
series: [
{
// false的时候遇到无效值端口,true则忽略
connectNulls: false,
name:'用电量',
type:'line',
smooth: true,
data: [300, 280, 250, 260, 270,'-', 300, 550, 500, 400, 390, 380, 390, 400, 500, 600, 750, 800, 700, 600, 400], //无效值 ‘-’
}
]
};
结果图如下:
(二)利用 visualMap 属性,将某一断是可以自定义的。 即设置某段colorAlpha 为0。
option = {
title: {
text: '一天用电量分布',
subtext: '纯属虚构'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
toolbox: {
show: true,
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['00:00', '01:15', '02:30', '03:45', '05:00', '06:15', '07:30', '08:45', '10:00', '11:15', '12:30', '13:45', '15:00', '16:15', '17:30', '18:45', '20:00', '21:15', '22:30', '23:45']
},
yAxis: {
type: 'value',
axisLabel: {
formatter: '{value} W'
},
axisPointer: {
snap: true
}
},
visualMap: [{
seriesIndex:0,
show: false,
dimension: 0,
inRange: { colorAlpha:0,},
outOfRange:{color:['blue']},
pieces: [
{
gt: 4,
lte: 5,
},
]
}],
series: [
{
name:'用电量',
type:'line',
smooth: true,
data: [300, 280, 250, 260, 270, 300, 550, 500, 400, 390, 380, 390, 400, 500, 600, 750, 800, 700, 600, 400],
},
{
name:'用电量',
type:'line',
smooth: true,
data: [200, 180, 150, 160, 170, 200, 450, 400, 300, 290, 280, 290, 300, 400, 500, 650, 700, 400, 400, 300],
}
]
};