forked from MapComplete/MapComplete
Refactoring: port ChartJS to Svelte
This commit is contained in:
parent
ca4f7566e2
commit
1d48d935ba
7 changed files with 333 additions and 339 deletions
21
src/UI/Base/ChartJs.svelte
Normal file
21
src/UI/Base/ChartJs.svelte
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<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}
|
||||
Loading…
Add table
Add a link
Reference in a new issue