forked from MapComplete/MapComplete
22 lines
470 B
Svelte
22 lines
470 B
Svelte
|
|
<script lang="ts">
|
||
|
|
import { onMount } from "svelte"
|
||
|
|
import { Chart, registerables } from "chart.js"
|
||
|
|
import type { ChartConfiguration } from "chart.js"
|
||
|
|
|
||
|
|
Chart?.register(...(registerables ?? []))
|
||
|
|
|
||
|
|
export let config: ChartConfiguration<TType, TData, TLabel>
|
||
|
|
let canvas: HTMLCanvasElement
|
||
|
|
onMount(() => {
|
||
|
|
if (canvas) {
|
||
|
|
new Chart(canvas, config)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
</script>
|
||
|
|
|
||
|
|
{#if config}
|
||
|
|
<canvas bind:this={canvas} />
|
||
|
|
{:else}
|
||
|
|
<slot name="empty" />
|
||
|
|
{/if}
|