ECharts error: Uncaught Error: `setOption` should not be called during main process

created at 11-11-2021 views: 53

error

Echarts data graphics rendering, the amount of graphics data is relatively large, after rendering, click on the graphics to optimize the rendering, the amount of data may be large, and an uncaught error occurs during re-rendering: setOption should not be called in the main process

reason

This error, the code is definitely no problem, because the first time the default loading is normal display, but there is a problem when re-rendering.

This is to limit the time when setOption is called. If the process of setOption or dispatchAction is not finished, calling setOption again in the middle will loop once.

Looking at the relevant information, there is a method to set the setOption delay that seems to be feasible, but the time given to me is very long and it is useless. I can only find another way out. This reason must be repeated when Echarts was drawing the picture, because when I first initialized the first picture, it was rendered normally. What if I failed to redraw the picture after the query? Is it possible to erase and redraw the previous Echarts diagram?

solution

It is possible in theory, but also in practice. I found a clear method in Echarts. Just do `clear` before setOption and execute setOption: the code is as follows:

myChart1.clear();
myChart1.setOption(option);

The method of passing time delay:

setTimeout(myCHart1.setOption(option), 500);
created at:11-11-2021
edited at: 11-11-2021: