在echart初始化函数外加个延时就可以:
加上延时会进入异步队列,同步可能获取不到dom
setTimeout(() => {
init2();
}, 1);
function init2() {
var chartDom = document.getElementById("Node2");
var myChart = echarts.init(chartDom);
var option;
option = {
tooltip: {
trigger: "item",
},
legend: {
top: "0%",
// bottom:"5%",
left: "center",
textStyle: {
color: "#ffffff",
},
},
series: [
{
// name: "能耗",
type: "pie",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
label: {
show: false,
position: "center",
},
emphasis: {
label: {
show: true,
fontSize: "40",
fontWeight: "bold",
},
},
labelLine: {
show: false,
},
data: haoneng.value,
},
],
};
option && myChart.setOption(option);
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_52691965/article/details/123813552
内容来源于网络,如有侵权,请联系作者删除!