window.customElements.define('chart-js', class extends HTMLElement {
    constructor() {
        super();
        const canvas = document.createElement('canvas');
        canvas.width = 400;
        canvas.height = 200;
        this.appendChild(canvas);
        this.ctx = canvas.getContext('2d');
    }

    initChart(type, dataString) {
        const config = JSON.parse(dataString);
        this.chart = new Chart(this.ctx, {
            type: type,
            data: config.data,
            options: config.options || {}
        });
    }

    updateChart(dataString) {
        const config = JSON.parse(dataString);
        this.chart.data = config.data;
        this.chart.options = config.options || {};
        this.chart.update();
    }
});