解决方案一:
不使用showloading,判断传入数据是否为空。
若数据为空,覆盖一层div。
若数据不为空,则隐藏div
解决方案2:
利用echarts的graphic。初始化是加入graphic。有数据时再利用id移除掉graphic。
初始化时:
在setoption中加入:
graphic:[
{
type: 'group',
id:'inittext',
left: '1%',
top: 'center',
children: [
{
type: 'rect',
z: 100,
left: 'center',
top: 'middle',
shape: {
width: 500,
height: 242,
},
style: {
fill: 'rgba(0,0,0,0.01)',
}
},
{
type: 'text',
z: 100,
left: 'center',
top: 'middle',
style: {
fill: '#000',
text: [
'暂无数据',
].join('\n'),
font: '14px Microsoft YaHei'
}
}
]
}
],
在有数据的setoption中加入:
graphic:[
{
id:'inittext',
$action:'remove',
}
],
参考链接:https://www.w3cschool.cn/echarts_tutorial/echarts_tutorial-3u872dym.html
https://echarts.baidu.com/option.html#graphic.elements-group.bounding
https://www.echartsjs.com/gallery/editor.html?c=line-graphic