he wei
2025-06-03 a10f3b82e33756ed0cd62a0cbe83bab8674df16f
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<script setup>
    import { onMounted, ref, watchEffect, nextTick, onBeforeUnmount } from "vue";
    import * as echarts from 'echarts';
 
 
 
 
    function getOptions() {
        let option = {
            backgroundColor: '#001037',
            grid: {
                top: '10%',
                left: '5%',
                right: '2%',
                bottom: '14%',
            },
            tooltip: {
                show: false,
            },
            xAxis: {
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                axisLine: {
                    lineStyle: {
                        color: 'transparent', //底部边框颜色
                    },
                },
                axisLabel: {
                    textStyle: {
                        color: '#fff', //底部文字颜色
                        fontSize: 12,
                    },
                },
            },
            yAxis: [
                {
                    type: 'value',
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: 'rgba(255,255,255,0.2)', //网格线的颜色
                            width: 1,
                            type: 'solid',
                        },
                    },
                    axisLine: {
                        show: false,
                        lineStyle: {
                            color: 'transparent', //左边框颜色
                        },
                    },
                    axisLabel: {
                        show: true,
                        fontSize: 12,
                        textStyle: {
                            color: '#ADD6FF', //左文字颜色
                        },
                    },
                },
            ],
            series: [
                {
                    name: '毕业学员',
                    type: 'bar',
                    barWidth: 30,
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(21,136,209,0.1)',
                        // color: '#f00',
                    },
                    itemStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                {
                                    offset: 0,
                                    // color: '#00FFE3',//渐变1
                                    color: 'rgba(21,136,209,1)', //渐变1
                                    // color: '#0f0', //渐变1
                                },
                                {
                                    offset: 1,
                                    // color: '#4693EC',//渐变2
                                    color: 'rgba(21,136,209,1)', //渐变2
                                    // color: '#0f0', //渐变2
                                },
                            ]),
                        },
                    },
                    data: [20, 80, 100, 40, 34, 90, 60, 20, 80, 100, 40, 34],
                    z: 0,
                    zlevel: 0,
                },
                {
                    type: 'pictorialBar',
                    barWidth: 30,
                    itemStyle: {
                        normal: {
                            color: 'rgba(0,63,119,1)', //数据的间隔颜色
                            // color: '#f00', //数据的间隔颜色
                        },
                    },
                    symbolRepeat: 'fixed',
                    symbolMargin: 3,
                    symbol: 'rect',
                    symbolSize: [30, 4],
                    symbolPosition: 'end',
                    symbolOffset: [0, 0],
                    data: [20, 80, 100, 40, 34, 90, 60, 20, 80, 100, 40, 34],
                    z: 1,
                    zlevel: 0,
                },
            ],
        };
 
        return option;
    }
 
    let myChart;
    const chartContainer = ref();
 
    function initChart() {
        if (chartContainer.value) {
            myChart = echarts.init(chartContainer.value, "custom", {
                rendererOptions: {
                    eventListenerOptions: {
                        passive: true // 启用被动事件监听器
                    }
                }
            });
 
 
            let option = getOptions();
            myChart.setOption(option);
 
            // 监听窗口变化重新渲染图表
            window.addEventListener("resize", () => {
                myChart.resize();
            });
        }
    }
 
    function updateChart(xLabels, datas) {
        let option = getOptions(xLabels, datas);
        myChart.setOption(option);
    }
 
    onMounted(() => {
        initChart();
    });
</script>
 
<template>
  <div class="chart-wraper">
    <div class="chart" ref="chartContainer"></div>
  </div>
</template>
 
<style scoped lang="less">
.chart-wraper {
  height: 100%;
  position: relative;
 
  .chart {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
  }
}
</style>