echarts数据渲染时横坐标是动态的,查询出来的数据需要按横坐标填充,没有的就设置为0
let doctorMap= new Map();
let nurseMap= new Map();
this.xAxisList=['00', '01', '02', '03', '04', '05', '06', '07', '08',
'09', '10', '11', '12', '13', '14', '15', '16', '17', '18',
'19', '20', '21', '22', '23'
]
//1.数组对象转map
res.data.ret?.doctorList.forEach(item=>doctorMap.set(item.TIME_HOUR,item.count));
res.data.ret?.nurseList.forEach(item=>nurseMap.set(item.TIME_HOUR,item.count));
let doctorArray = []
let nurseArray = []
this.xAxisList.forEach(x_item=>{
//判断map中是否存在某值
if(doctorMap.has(x_item)){
doctorArray.push(doctorMap.get(x_item))
}else{
doctorArray.push(0)
}
if(nurseMap.has(x_item)){
nurseArray.push(nurseMap.get(x_item))
}else{
nurseArray.push(0)
}
})
this.setChart(doctorArray, nurseArray)