2024-02-02 13:00:54 +00:00
|
|
|
<script lang="ts" setup>
|
2023-10-31 14:38:43 +00:00
|
|
|
import { ref, watch, computed, onMounted } from 'vue';
|
2024-02-02 13:00:54 +00:00
|
|
|
import { Chart, LineElement, PointElement, LineController, LinearScale, CategoryScale, Tooltip, registerables } from 'chart.js';
|
|
|
|
import { Ref } from 'vue';
|
|
|
|
import { ChartDataCustomTypesPerDataset } from 'chart.js';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2024-02-02 13:00:54 +00:00
|
|
|
|
|
|
|
// interface Dataset {
|
|
|
|
|
|
|
|
// borderColor: string;
|
|
|
|
// // borderDash:
|
|
|
|
// // (0) []
|
|
|
|
// borderDashOffset: number;
|
|
|
|
// borderWidth: number;
|
|
|
|
// cubicInterpolationMode: string;
|
|
|
|
// data: Array<number>;
|
|
|
|
// fill: boolean;
|
|
|
|
// pointBackgroundColor: string;
|
|
|
|
// pointBorderColor: string;
|
|
|
|
// pointBorderWidth: number;
|
|
|
|
// pointHoverBackgroundColor: string;
|
|
|
|
// pointHoverBorderWidth: number;
|
|
|
|
// pointHoverRadius: number;
|
|
|
|
// pointRadius: number;
|
|
|
|
// tension: number;
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
const props = defineProps({
|
2023-10-31 14:38:43 +00:00
|
|
|
data: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2024-02-02 13:00:54 +00:00
|
|
|
const root: Ref<HTMLCanvasElement | null> = ref<HTMLCanvasElement | null>(null);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
let chart;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
Chart.register(LineElement, PointElement, LineController, LinearScale, CategoryScale, Tooltip);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
2024-02-02 13:00:54 +00:00
|
|
|
Chart.register(...registerables);
|
|
|
|
|
|
|
|
// https://gitea.geologie.ac.at/kaiarn/geomon.viewer/src/branch/master/src/common/graphjs/geomon-timeseries-chart/geomon-timeseries-chart.component.ts
|
2023-10-31 14:38:43 +00:00
|
|
|
chart = new Chart(root.value, {
|
|
|
|
type: 'line',
|
2024-02-02 13:00:54 +00:00
|
|
|
data: props.data as ChartDataCustomTypesPerDataset<"line", number[], string>,
|
|
|
|
// data: {
|
|
|
|
// labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
|
|
|
// // labels: [],
|
|
|
|
// datasets: [
|
|
|
|
// {
|
|
|
|
// data: [86, 114, 106, 106, 107, 111, 133, 221, 783, 2478, 2600, 2700],
|
|
|
|
// label: "Africa",
|
|
|
|
// borderColor: "#3e95cd",
|
|
|
|
// fill: false
|
|
|
|
// }, {
|
|
|
|
// data: [282, 350, 411, 502, 635, 809, 947, 1402, 3700, 5267, 444, 555],
|
|
|
|
// label: "Asia",
|
|
|
|
// borderColor: "#8e5ea2",
|
|
|
|
// fill: false
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
// },
|
|
|
|
|
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
options: {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
scales: {
|
|
|
|
y: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
x: {
|
|
|
|
display: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
2024-02-02 13:00:54 +00:00
|
|
|
display: true,
|
2023-10-31 14:38:43 +00:00
|
|
|
},
|
|
|
|
},
|
2023-03-03 15:54:28 +00:00
|
|
|
},
|
2023-10-31 14:38:43 +00:00
|
|
|
});
|
2024-02-02 13:00:54 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const chartData = computed(() => props.data);
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
watch(chartData, (data) => {
|
|
|
|
if (chart) {
|
|
|
|
chart.data = data;
|
|
|
|
chart.update();
|
|
|
|
}
|
|
|
|
});
|
2023-03-03 15:54:28 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-10-31 14:38:43 +00:00
|
|
|
<canvas ref="root" />
|
2023-03-03 15:54:28 +00:00
|
|
|
</template>
|