When the browser executes document.getElementById(‘chart’), because the dom object with the id of main has not been created, it reports an error Initialize failed: invalid dom.
The solution is to delay the execution of the code for initializing the charts in echarts, which is fast and does not affect the display of the effect and does not feel stuck.
func.echarts() for the initialization of the chart function , code and effects are as follows (a vue3.0 project of a page used)
echarts: () => {
let myChart = echarts.init(document.getElementById("chart"));
let option = {
title: {
text: '标题',
textStyle: {
fontSize: 13
},
},
toolbox: {
show: true,
feature: {
saveAsImage: {
show: false
}
},
},
legend: {
data: ['人数']
},
xAxis: {
data: ['09-14', '09-15', '09-16', '09-17', '09-18', '09-19', '09-20']
},
yAxis: {},
series: [{
name: '人数',
type: 'line',
data: ['13', '14', '18', '14', '10', '11', '9'],
}]
};
myChart.setOption(option);
},
})
Read More:
- [Solved] Echarts Error: Uncaught (in promise) Error: Initialize failed: invalid dom.
- Vue-echarts error: was not found in vue-demi [How to Solve]
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error
- Vue: initialize failed: invalid DOM [How to Solve]
- Echarts Partially introduced error: TypeError: Cannot read property ‘findAxisModel’ of undefined
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)
- Vant Applet: The Usage of Vant-dialog in Before-close
- How to Block a frame with origin from accessing a cross origin frame
- Asynchronous loading method of Baidu map
- How to Solve the error: initialize failed invalid dom
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- The solution to the failure of HTML introducing external JS
- CSS to achieve dynamic display of picture text by mouse touch
- [Solved] Vue echarts Error: Initialize failed: invalid dom.
- [Solved] Cannot read properties of undefined (reading ‘propsData‘)“
- [Solved] Vue E-Charts Error: These dependencies were not found:
- [Solved] Syntax Error: Error: No ESLint configuration found & TypeError: eslint.CLIEngine is not a constructor
- How to Fix Taro SwipeAction Not Working Issue
- Vue cannot read property ‘xxx’ of undefined solutions