-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to use ApexCharts.js as web-component #1332
Comments
|
Ok, found the workaround. It basically disables class LineChart extends LitElement {
// ...
createRenderRoot() {
return this;
}
async renderChart({ series, xaxis }) {
await this.updateComplete;
var options = { /* ... */ };
const div = document.createElement('div');
this.appendChild(div);
var chart = new ApexCharts(div, options);
chart.render();
}
render() {}
} |
hi @ulshv , i've never worked with Do you know what I'm doing wrong? |
Hi @ulshv thanks for creating this issue. I'm trying to do something similar with LitElement. Did you run into any issues with ApexCharts css not being loaded / accessed? Thanks. |
I was able to directly load the css within the render method.
However, this approach is strongly not recommended by LitElement. I also tried copying the entire css into the elements
|
That is only a workaround if you don’t actually need the Shadow DOM. |
Here's a workaround that enables Apex Charts to work in Shadow DOM (but reduces browser support to those that support let ros = new WeakMap();
window.addResizeListener = function(el, fn) {
let called = false;
let ro = new ResizeObserver(r => {
if (called) { // We don't want to call it immediately
fn.call(el, r);
}
called = true;
});
if (el.nodeType === Node.DOCUMENT_FRAGMENT_NODE){
// Observe children instead
Array.from(el.children).forEach(c => ro.observe(c));
}
else {
ro.observe(el);
}
ros.set(fn, ro);
};
window.removeResizeListener = function(el, fn) {
let ro = ros.get(fn);
if (ro) {
ro.disconnect();
ros.delete(fn);
}
} The code would need to run after Apex Charts are imported, to correctly override the It's just something I put together right now, and has not been extensively tested, but it's a starting point. (You'd still need to work around the CSS not being imported properly, see #238) |
Great lib! Anyways, I'm not able to use it in new project which is based on web-components with LitElement. It's throwing this error:
Code example:
The text was updated successfully, but these errors were encountered: