单个柱子
const data = [
{
value: 1,
per: 2
},
{
value: 22,
per: 2
},
{
value: 222,
per: 3
}
];
tooltip: {
trigger: 'axis',
show: true,
axisPointer: {
type: 'line',
lineStyle: {
color: 'rgba(0, 0, 0, 0.03)',
type: 'solid',
width: 60,
},
},
formatter(params) {
return `${params[0].name}: ${params[0].value}元 | ${data[params[0].dataIndex].per}%`;
},
transitionDuration: 0, // 让toolltip紧跟鼠标,移入页面不抖动
},
多个柱子堆叠
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
label: {
show: true,
color: '#4E5258',
},
},
formatter(params) {
const xname = params[0].axisValue;
let str = `${xname}<br>`;
params.forEach((el, index) => {
str += `${el.marker}${el.seriesName.split('(')[0]}:${el.value}元<br>`;
});
return str;
},
transitionDuration: 0, // 让toolltip紧跟鼠标,移入页面不抖动
},