您可以使用两个不同的堆栈来实现给定的外观,一个用于阳性,一个用于负部分。所得条可以与barGap: "-100%"
重叠。请注意,将蓝条切成两块,在使用Legend或Tooltip时可能会使事情变得复杂。
const data = [{
time: 1,
blue: 48,
green_pos: 0,
green_neg: 0,
yellow_pos: 0,
yellow_neg: 0
}, ... ];
option = {
xAxis: {
type: 'category',
},
yAxis: { type: 'value' },
series: [
{
name: 'blue_pos',
type: 'bar',
stack: 'pos',
data: data.map(x => x.blue / 2),
color: '#5470c6'
},
{
name: 'blue_neg',
type: 'bar',
stack: 'neg',
data: data.map(x => -x.blue / 2),
color: '#5470c6'
},
{
name: 'green_pos',
type: 'bar',
stack: 'pos',
data: data.map(x => x.green_pos),
color: '#91cc75'
},
{
name: 'green_neg',
type: 'bar',
stack: 'neg',
data: data.map(x => -x.green_neg),
color: '#91cc75'
},
{
name: 'yellow_pos',
type: 'bar',
stack: 'pos',
data: data.map(x => x.yellow_pos),
color: '#fac858'
},
{
name: 'yellow_neg',
type: 'bar',
stack: 'neg',
data: data.map(x => -x.yellow_neg),
color: '#fac858',
barGap: "-100%"
},
]
};