summaryrefslogtreecommitdiff
path: root/ping/frontend/src/lib/components/SteppedLineChart.svelte
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /ping/frontend/src/lib/components/SteppedLineChart.svelte
add: added projectsHEADmain
Diffstat (limited to 'ping/frontend/src/lib/components/SteppedLineChart.svelte')
-rw-r--r--ping/frontend/src/lib/components/SteppedLineChart.svelte76
1 files changed, 76 insertions, 0 deletions
diff --git a/ping/frontend/src/lib/components/SteppedLineChart.svelte b/ping/frontend/src/lib/components/SteppedLineChart.svelte
new file mode 100644
index 0000000..d393b44
--- /dev/null
+++ b/ping/frontend/src/lib/components/SteppedLineChart.svelte
@@ -0,0 +1,76 @@
+<script lang="ts">
+ import {
+ Chart,
+ CategoryScale,
+ LinearScale,
+ PointElement,
+ LineElement,
+ Title,
+ Tooltip,
+ Legend,
+ LineController
+ } from 'chart.js';
+ import { onMount } from 'svelte';
+
+ Chart.register(
+ CategoryScale,
+ LinearScale,
+ PointElement,
+ LineElement,
+ Title,
+ Tooltip,
+ Legend,
+ LineController
+ );
+
+ interface IProps {
+ color?: string;
+ data?: any[];
+ title?: string;
+ legend?: string;
+ }
+
+ const { color = 'green', data = [], title = '', legend = '' }: IProps = $props();
+
+ function updateGraph() {
+ const ctx = document.getElementById(id) as HTMLCanvasElement;
+ const chart = new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: data.map((d) => d.label),
+ datasets: [
+ {
+ label: legend,
+ data: data.map((d) => d.value),
+ borderColor: color,
+ backgroundColor: color,
+ fill: false,
+ tension: 0.1
+ }
+ ]
+ },
+ options: {
+ responsive: true,
+ plugins: {
+ title: {
+ display: true,
+ text: title
+ },
+ legend: {
+ display: true
+ }
+ }
+ }
+ });
+ }
+
+ const id = 'graph-' + crypto.randomUUID();
+
+ onMount(() => {
+ updateGraph();
+ });
+</script>
+
+<div>
+ <canvas {id}></canvas>
+</div>