mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 17:06:01 +00:00
chart initial import
This commit is contained in:
34
packages/web/src/charts/ChartCore.svelte
Normal file
34
packages/web/src/charts/ChartCore.svelte
Normal 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} />
|
||||
Reference in New Issue
Block a user