class CustomChart extends HTMLElement { constructor () { super(); this.attachShadow({ mode: "open" }); this.shadowRoot.innerHTML = `
`; this.responsiveStyle = this.shadowRoot.querySelector("#responsive-style"); this.canvas = this.shadowRoot.querySelector("canvas"); this.caption = this.shadowRoot.querySelector("figcaption"); } set data (data) { if (data.chart?.options?.plugins?.title.display) { data.chart.options.plugins.title.display = false; for (let line of data.chart.options.plugins.title.text) { this.caption.innerHTML += `${line}` } } this.canvas.role = "img"; this.canvas.ariaLabel = data.ariaLabel; createChart(this.canvas, data.chart); } get data () { return null; } set responsive (breakpoint) { this.breakpoint = breakpoint; if (breakpoint) { this.responsiveStyle.media = `screen and (width <= ${breakpoint})`; } else { this.responsiveStyle.media = "not all"; } } get responsive () { return this.breakpoint; } } function createChart (ctx, data) { return new Chart(ctx, data); } customElements.define("custom-chart", CustomChart);