2025-11-27 19:08:41 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
2026-02-08 17:01:33 +08:00
|
|
|
import type { DashboardApi } from '#/api/dashboard';
|
2025-11-27 19:08:41 +08:00
|
|
|
|
2026-02-08 17:01:33 +08:00
|
|
|
import { onMounted, ref, watch } from 'vue';
|
2025-11-27 19:08:41 +08:00
|
|
|
|
|
|
|
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
|
|
|
|
|
2026-02-08 17:01:33 +08:00
|
|
|
interface Props {
|
|
|
|
|
data?: DashboardApi.TrendData[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const props = defineProps<Props>();
|
|
|
|
|
|
2025-11-27 19:08:41 +08:00
|
|
|
const chartRef = ref<EchartsUIType>();
|
|
|
|
|
const { renderEcharts } = useEcharts(chartRef);
|
|
|
|
|
|
2026-02-08 17:01:33 +08:00
|
|
|
const updateChart = () => {
|
|
|
|
|
if (!props.data || props.data.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dates = props.data.map((item) => item.date);
|
|
|
|
|
const values = props.data.map((item) => item.value);
|
|
|
|
|
|
2025-11-27 19:08:41 +08:00
|
|
|
renderEcharts({
|
|
|
|
|
grid: {
|
|
|
|
|
bottom: 0,
|
|
|
|
|
containLabel: true,
|
|
|
|
|
left: '1%',
|
|
|
|
|
right: '1%',
|
2026-02-08 17:01:33 +08:00
|
|
|
top: '2%',
|
2025-11-27 19:08:41 +08:00
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
areaStyle: {},
|
2026-02-08 17:01:33 +08:00
|
|
|
data: values,
|
2025-11-27 19:08:41 +08:00
|
|
|
itemStyle: {
|
|
|
|
|
color: '#5ab1ef',
|
|
|
|
|
},
|
|
|
|
|
smooth: true,
|
|
|
|
|
type: 'line',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
tooltip: {
|
|
|
|
|
axisPointer: {
|
|
|
|
|
lineStyle: {
|
2026-02-08 17:01:33 +08:00
|
|
|
color: '#5ab1ef',
|
2025-11-27 19:08:41 +08:00
|
|
|
width: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
},
|
|
|
|
|
xAxis: {
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
boundaryGap: false,
|
2026-02-08 17:01:33 +08:00
|
|
|
data: dates,
|
2025-11-27 19:08:41 +08:00
|
|
|
splitLine: {
|
|
|
|
|
lineStyle: {
|
|
|
|
|
type: 'solid',
|
|
|
|
|
width: 1,
|
|
|
|
|
},
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
type: 'category',
|
|
|
|
|
},
|
|
|
|
|
yAxis: [
|
|
|
|
|
{
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
splitArea: {
|
|
|
|
|
show: true,
|
|
|
|
|
},
|
|
|
|
|
splitNumber: 4,
|
|
|
|
|
type: 'value',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
2026-02-08 17:01:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.data,
|
|
|
|
|
() => {
|
|
|
|
|
updateChart();
|
|
|
|
|
},
|
|
|
|
|
{ deep: true },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
updateChart();
|
2025-11-27 19:08:41 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<EchartsUI ref="chartRef" />
|
|
|
|
|
</template>
|