apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.75k stars 19.62k forks source link

[Bug] node-canvas could not load image #19054

Open itzdrli opened 1 year ago

itzdrli commented 1 year ago

Version

5.4.3

Link to Minimal Reproduction

https://github.com/itzdrli/example

Steps to Reproduce

Use the code from Here. The code has written by following official document

Current Behavior

Error: C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:9083 for (var i = 0; i < cachedImgObj.pending.length; i++) { ^

TypeError: Cannot read properties of undefined (reading 'pending') at imageOnLoad (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:9083:42) at setSource (C:\Users\xxxx\Desktop\t\node_modules.pnpm\canvas@2.11.2\node_modules\canvas\lib\image.js:94:13) at Image.set (C:\Users\xxxx\Desktop\t\node_modules.pnpm\canvas@2.11.2\node_modules\canvas\lib\image.js:40:9) at Object.loadImage (C:\Users\xxxx\Desktop\t\index.js:16:13) at createOrUpdateImage (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:9067:37) at brushImage (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:27311:34) at brush (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:27627:17) at CanvasPainter._doPaintEl (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:40498:17) at repaint (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:40433:31) at _loop_1 (C:\Users\xxxx\Desktop\t\node_modules.pnpm\echarts@5.4.3\node_modules\echarts\dist\echarts.js:40464:21)

Expected Behavior

the image would show

Environment

- OS:Windows 11
- Node-Canvas

Any additional comments?

No response

helgasoft commented 1 year ago

not sure what you are trying to accomplish with loadImage since it is not used anywhere... Images could be used as background or symbols - Demo Code

ahdg6 commented 1 year ago

not sure what you are trying to accomplish with loadImage since it is not used anywhere... Images could be used as background or symbols - [Demo Code)

Check the code he provided, he is indeed using symbols. And if the image is not loaded, this error will not appear at all

Even when using the Demo code you provided, this error still occurs in node-canvas.

ahdg6 commented 1 year ago

wth, if you remove img.onload = onload.bind(img); it will works as intented. Possible related commit: https://github.com/ecomfe/zrender/commit/c564acd0b0619df9402790f67ae229c1e4ac8d8b

Anyway, the offical documentation are not written correctly. https://echarts.apache.org/handbook/en/how-to/cross-platform/server/#loading-of-images