chart initial import

This commit is contained in:
Jan Prochazka
2021-03-19 20:12:13 +01:00
parent 75c578de47
commit 489c9a905c
17 changed files with 617 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
<script lang="ts">
import { onMount, afterUpdate, onDestroy } from 'svelte';
import Chart from 'chart.js';
export let data;
export let type = 'line';
export let options = {};
export let plugins = {};
let chart = null;
let domChart;
onMount(() => {
chart = new Chart(domChart, {
type,
data,
options,
plugins,
});
});
afterUpdate(() => {
if (!chart) return;
chart.data = data;
chart.type = type;
chart.options = options;
chart.plugins = plugins;
chart.update();
});
onDestroy(() => {
chart = null;
});
</script>
<canvas bind:this={domChart} {...$$restProps} />