gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
echarts.js:1 Dom’s width & height should be ready before init.
- User
echarts.js:1 Dom’s width & height should be ready before init.
- Assistant
To ensure that the width and height of the DOM element are ready before initializing ECharts, you can use the
Windowobject'sloadevent or theDOMContentLoadedevent. Here's an example:window.addEventListener('DOMContentLoaded', function () { // Get the DOM element var dom = document.getElementById('chart'); // Initialize ECharts var myChart = echarts.init(dom); // Set the width and height of the chart myChart.resize(); // Use the chart // ... });In this example, the
DOMContentLoadedevent is fired when the initial HTML document has been completely loaded and parsed, without waiting for images and external resources. Once the event fires, you can safely access the DOM element, initialize ECharts, and set its width and height.