class ChartWidget extends HTMLElement {
connectedCallback() {
const config = JSON.parse(this.getAttribute('config') || '{}');
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
${config.title}
`;
if (window.ApexCharts) {
this.initChart(config);
}
}
initChart(config) {
const chart = new ApexCharts(this.shadowRoot.querySelector('#chart'), {
chart: { type: config.type || 'line', height: '100%' },
series: config.series || [],
xaxis: config.xaxis || {},
});
chart.render();
}
}
customElements.define('chart-widget', ChartWidget);