Chart.js
Chart.js copied to clipboard
defaultView is null (Firefox and Chromium / chart.js 4.3)
Expected behavior
Code running without errors.
Current behavior
When executing code, the following error occurs :
Uncaught TypeError: element.ownerDocument.defaultView is null
getComputedStyle helpers.segment.js:2161
getStyle helpers.segment.js:2163
readUsedSize helpers.segment.js:2351
initCanvas chart.js:3227
acquireContext chart.js:3381
Chart chart.js:5602
Reproducible sample
None
Optional extra steps/info to reproduce
No response
Possible solution
Rewrite the function getComputedStyle in "chart.js/dist/chunks/helpers.segment.js:2161" as follow :
const getComputedStyle = (element)=>element.ownerDocument.defaultView?.getComputedStyle(element, null) ?? { getPropertyValue: () => null };
Context
I had a code that worked, then I upgraded Chart.js npm package.
chart.js version
v4.3.0
Browser name and version
Firefox 113.0.2 / Chromium 114.0.5735.106
Link to your project
No response
Related issues :
- https://github.com/chartjs/Chart.js/issues/5300
- https://github.com/chartjs/Chart.js/issues/1032
Also running into this issue with the desktop GUI framework, Sciter.js
Downgrading to 3.x fixed it.
I have the same issue