forked from drone/command-center-dashboard

罗广辉
2025-04-21 2800fa4f32f3900509cb4d6eefaf2bfaf54efdd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<template>
    <div class="event-trend-analysis">
        <div class="little-title">事件趋势分析</div>
        <div class="chart" ref="echartsRef"></div>
    </div>
</template>
<script setup>
import { getEventTrend } from '@/api/home/event'
import * as echarts from 'echarts'
import useEchartsResize from '@/hooks/useEchartsResize'
 
const echartsRef = ref(null)
let { chart } = useEchartsResize(echartsRef)
 
const echartsOption = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
        },
    },
    grid: {
        top: '5%',
        left: 0,
        right: 0,
        bottom: 0,
        containLabel: true,
    },
    xAxis: {
        type: 'category',
        axisLabel: {
            // rotate: -45, // 旋转角度
            // interval: 0, // 显示所有标签
            color: '#FFFFFF',
            fontFamily: 'Source Han Sans CN, Source Han Sans CN',
            fontWeight: 400,
            fontSize: 10,
        },
        data: [],
    },
    yAxis: [
        {
            type: 'value',
            axisLabel: {
                interval: 0, // 显示所有标签
                color: '#FFFFFF',
                fontFamily: 'Source Han Sans CN, Source Han Sans CN',
                fontWeight: 400,
                fontSize: 10,
            },
            axisLine: {
                lineStyle: {
                    color: '#ffffff',
                },
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255, 255, 255, 0.1)',
                    type: 'dashed', // 设置为虚线
                },
            },
        },
    ],
    series: {
        type: 'line',
        itemStyle: {
            color: '#0CEBF7', // 设置颜色
        },
        lineStyle: {
            width: 2, // 线条宽度
            type: 'solid', // 线条类型
        },
        symbol: 'circle', // 数据点符号
        symbolSize: 6, // 数据点符号大小
        emphasis: {
            focus: 'series',
        },
        areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                    offset: 0,
                    color: 'rgba(24, 141, 240, 0.4)', // 顶部颜色
                },
                {
                    offset: 1,
                    color: 'rgba(24, 141, 240, 0)', // 底部颜色
                },
            ]),
        },
        data: [], // 示例数据,根据实际完成率计算
    },
}
 
const params = inject('eventOverviewParams')
 
watch(params, () => {
    getData()
})
 
// 获取数据
const getData = async () => {
    const res = await getEventTrend(params.value)
    const list = res?.data?.data || []
    echartsOption.xAxis.data = list.map(item => item.name)
    echartsOption.series.data = list.map(item => item.value)
    chart.value.setOption(echartsOption)
}
 
onMounted(() => {
    getData()
})
</script>
<style scoped lang="scss">
.event-trend-analysis {
    height: 280px;
}
.little-title {
        background: url('@/assets/images/little-title-bg.png') no-repeat center / 100% 100%;
        width: 372px;
        height: 28px;
        line-height: 28px;
        padding-left: 16px;
        font-size: 14px;
    }
.chart {
    margin-top: 10px;
    width: 356px;
    height: 240px;
}
</style>