第1种:配置background属性
这种是最简单的,这样配置一下就好
{
type: 'bar',
data: data,
showBackground: true,
backgroundStyle: {
color: 'rgba(53,119,218,0.3)'
}
},
但是用这种达不到这种效果
第2种:使用barGap
这种用来做背景确实可以,但是要计算y轴max等等,还要处理tooltip,反正就很麻烦
第3种:多轴
额外增加一个x轴
{
type: 'category',
data: data.map(i=>''),
},
然后设置bar关联这个轴,不用name,这样就可以了,设置方便也快速
{
type: 'bar',
barWidth: '80%',
data: data.map(i => ''),
tooltip: { show: false }, // 仅禁用该系列的Tooltip
xAxisIndex: 1, // 核心在这里
showBackground: true,
backgroundStyle: {
color: 'rgba(53,119,218,0.3)'
}
},