chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
63.94k stars 11.89k forks source link

Lightning Web Integration #11652

Closed AmineId closed 5 months ago

AmineId commented 5 months ago

Expected behavior

Previously with ChartJS v2, we could call the constructor Chart from window, since we override the loading of the framework.

Current behavior

I wanted to use ChartJs v4 on a new project, but the window.Chart is not resolved.

Reproducible sample

https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js

Optional extra steps/info to reproduce

No response

Possible solution

I tried running a new recompile to add the binding with window, but the projet has evolved soo much I was lost :D

Is there a way (fast way) to do the binding with window ?

Context

No response

chart.js version

v4.4.1

Browser name and version

No response

Link to your project

No response

LeeLenaleee commented 5 months ago

Hi @AmineId when I try to access window.Chart it works perfectly fine. Can you add a reproducable example as stateted in the issue template as being required?

https://jsfiddle.net/vLh5eu9y/

AmineId commented 5 months ago

Hi @LeeLenaleee, sorry for not being able to provide a template, since I'm working in Salesforce :/

For my case, I was able to get it to work, since I'm in Shadow DOM with an extra layer of security (Salesforce by default locked all LWC -component created for web like in Angular or Vue- from being visible to Third-Party Plugins), I just disabled the Lock features and I could use chartJs normally. But this only because I did have the option to do that (only when creating website to be used by Customer - it's some sort of cloud in Salesforce EcoSystem)

I need to do some tests to validate my theory, but for an Experience Cloud (a tag for any Salesforce developer with the issue) usage this is the work around :)

Thanks a lot for the reply, I'll keep you posted :D, for now I'll close the issue