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.
- [Solved] Vue echarts Error: Initialize failed: invalid dom.
- [Solved] echarts Error: Error in callback for watcher “chartSource“: “Error: Initialize failed: invalid dom.“
- Vue: initialize failed: invalid DOM [How to Solve]
- [Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit
- How to Solve the error: initialize failed invalid dom
- Vue-echarts error: was not found in vue-demi [How to Solve]
- Echarts Map Error: Error: Invalid geoJson format Cannot read property ‘length‘ of undefined
- [Solved] Echarts Error: TypeError: Cannot read properties of null (reading getAttribute )
- Echarts Partially introduced error: TypeError: Cannot read property ‘findAxisModel’ of undefined
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;
- The addition, deletion and modification of DOM in JS Foundation
- [Solved] vue-roter 4 Error: Error: Invalid route component/Uncaught (in promise) Error: Invalid route component
- [Solved] Uncaught (in promise) DOMException: Failed to load because no supported source was found.
- [Solved] Echarts Error: Cannot read property ‘init‘ of undefined
- How to solve Uncaught (in promise) error in VUE?
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- [Solved] Uncaught (in promise) Error: Avoided redundant navigation to current location:
- [Solved] Uncaught (in promise) TypeError: XXX.a is not a constructor
- Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to crrent location: “/home“