series里面新增一个总数项,设置barGap: '-100%'
{
name: '总数',
data: he.value,
type: 'bar',
barGap: '-100%',
itemStyle: {
normal: {
color: '#F5B763',
label: {
show: true, // 开启显示数值
position: 'top', // 数值在上方显示
textStyle: { // 数值样式
color: '#000', // 字体颜色
fontSize: '12px', // 字体大小
},
},
},
},
barWidth: '15px',
},
如果不想在tooltip显示总数项
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
formatter: (params) => {
let res = `${params[0].name} <br/>`
for (const item of params) {
console.log(item, 'item')
if (item.seriesName !== '总数')
res += `<span style="background: ${item.color}; height:10px; width: 10px; border-radius: 50%;display: inline-block;margin-right:10px;"></span> ${item.seriesName} :${item.value}<br/>`
}
return res
},
},