这里我们的需求是在tooltip里显示后台给的多条数据,所以tooltip里面的formatter里的数据就得自己放进去,我这里是放进了series里data里面,然后在formatter里面去取的
if (bankNameArr.length == 1) {
let series = [];
let num = 0;
bankNameArr.forEach((ele) => {
let yData = [];
for (let i = 0; i < this.xData.length; i++) {
for (let j = 0; j < dataArr.length; j++) {
if (this.xData[i] == dataArr[j].date) {
for (
let m = 0;
m < dataArr[j].list.length;
m++
) {
if (ele == dataArr[j].list[m].name) {
yData.push({
duration:
dataArr[j].list[m].duration,
people:
dataArr[j].list[m].people,
value:
dataArr[j].list[m].duration,
});
}
}
}
}
}
series.push(
{
name: ele,
type: "bar",
barMaxWidth: "45",
data: yData,
},
{
name: ele,
type: "line",
stack: num++,
areaStyle: {
opacity: 0,
},
barMaxWidth: "45",
data: yData,
}
);
});
this.initChartBarPeople(series); //获取到数据渲染echarts
}
其中,value是柱状图需要展示的数据,其他两个字段是需要展示在tooltip提示框里的
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
textStyle: {
color: "#999",
align: "left",
},
position: ["30%", "30%"],
extraCssText:
"box-shadow:0px 0px 8px 0px rgba(176,176,176,1)",
backgroundColor: "#fff",
formatter: function (params) {
console.log(params);
//去除重复数据
for (var i = 0; i < params.length; i++) {
for (var j = params.length - 1; j > i; j--) {
if (
params[j].seriesName == params[i].seriesName
) {
params.splice(j, 1);
break;
}
}
}
// console.log(params);
var res = "";
for (var i = 0; i < params.length; i++) {
// console.log(params);
var data = "<p>" + params[i].name + "</p>";
res +=
"<p>" +
params[i].marker +
params[i].seriesName +
":" +
"</br>" +
" " +
"办理时长:" +
params[i].data.duration +
"(分)" +
"</br>" +
" " +
"总客流量:" +
params[i].data.people +
"(人)" +
"</p>";
}
return data + res;
},
},
然后在tooltip里的formatter展示格式,显示出来
以上仅代表个人观点,如有错误,欢迎指正