diff --git a/shared/widgets/iot-chart/widget.ts b/shared/widgets/iot-chart/widget.ts index 0bdd396..acfd959 100644 --- a/shared/widgets/iot-chart/widget.ts +++ b/shared/widgets/iot-chart/widget.ts @@ -264,7 +264,8 @@ export class IotChartElement extends HTMLElement { type === 'stepline' ? 'stepline' : 'smooth'; const seriesData = this.#series.map((s, i) => ({ - name: s.label ?? s.key, + // ApexCharts writes series names into the tooltip as HTML. + name: escapeHtml(s.label ?? s.key), color: s.color ?? PALETTE[i % PALETTE.length]!, data: s.points.map((p) => ({ x: p.ts * 1000, y: p.value })), })); @@ -386,3 +387,7 @@ function formatNumber(v: number): string { function isDark(): boolean { return typeof document !== 'undefined' && document.documentElement.classList.contains('dark'); } + +function escapeHtml(s: string): string { + return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c] ?? c); +}