2023-03-03 15:54:28 +00:00
|
|
|
<script setup>
|
2023-10-31 14:38:43 +00:00
|
|
|
import { ref, watch, computed, onMounted } from 'vue';
|
|
|
|
import { Chart, LineElement, PointElement, LineController, LinearScale, CategoryScale, Tooltip } from 'chart.js';
|
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
|
|
|
|
2023-10-31 14:38:43 +00:00
|
|
|
const root = ref(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(() => {
|
2023-10-31 14:38:43 +00:00
|
|
|
chart = new Chart(root.value, {
|
|
|
|
type: 'line',
|
|
|
|
data: props.data,
|
|
|
|
options: {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
scales: {
|
|
|
|
y: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
x: {
|
|
|
|
display: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
},
|
2023-03-03 15:54:28 +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>
|