zhongrj
2026-06-02 0299e41c6692684d943b4a206472a86ea84ea4b5
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
171
172
 
<template>
    <div class="echarts-box" id="stackBarChart">
 
    </div>
</template>
 
<script>
export default {
    data () {
        return {
            myChart: null
        }
    },
 
    mounted () {
        // let stackBarData = {
        //     xAxisData: ["武汉市", "黄石市", "十堰市", "宜昌市", "襄阳市", "鄂州市", "荆门市", "孝感市"],
        //     seriesData_01: ["20", "30", "15", "1", "10", "8", "5", "18"],
        //     seriesData_02: ["2", "6", "5", "10", "10", "8", "5", "1"],
        //     seriesData_03: ["3", "5", "1", "10", "3", "9", "15", "1"],
        //     sum: 39,
        // }
        // this.$nextTick(() => {
        //     this.createStackBarChart(stackBarData)
        // })
    },
    destroyed () {
 
    },
    methods: {
        initEcharts (params) {
            this.$nextTick(() => {
                this.createStackBarChart(params)
            })
        },
 
        createStackBarChart (chartData) {
            if (!this.myChart) {
                this.myChart = this.$echarts.init(
                    document.getElementById('stackBarChart')
                )
            }
 
            // 指定图表的配置项和数据
            var option = {
                title: {
                    text: '总数' + chartData.sum + '座',
                    top: 10,
                    right: 20,
                    textStyle: {
                        color: "#BDD8F9",
                        fontSize: 16,
                        fontWeight: 400,
                    },
                },
                legend: {
                    show: true,
                    top: 10,
                    itemWidth: 8,
                    itemHeight: 8,
                    itemGap: 20,
                    left: "center",
                    textStyle: {
                        color: "#B5C5D4",
                        fontSize: 14,
                    },
                },
                tooltip: {
                    trigger: "axis",
                    backgroundColor: '#133260',
                    textStyle: {
                        color: '#fff',
                    },
                    axisPointer: {
                        type: "shadow"
                    },
                    formatter: function (e) {
                        if (e.length > 0) {
                            var t = "".concat(e[0].name + " <br/>")
                            e.forEach((item) => {
                                t += item.marker + item.seriesName + ": " + item.value + " 座 <br/>"
                            })
                            return t
                        }
                    }
                },
                xAxis: {
                    data: chartData.xAxisData,
                    name: "",
                    axisLine: {
                        onZero: true,
                        lineStyle: {
                            color: "rgba(186, 198, 208, .4)",
                        },
                    },
                    axisTick: {
                        show: false,
                    },
                    axisLabel: {
                        rotate: 30,
                        interval: 0,
                        fontSize: 10,
                        color: "#B5C5D4",
                    },
                },
                yAxis: {
                    name: '数量',
                    minInterval: 1,
                    axisLabel: {
                        fontSize: 10,
                        color: "#B5C5D4",
                    },
                    nameTextStyle: {
                        fontSize: 14,
                        color: "#B5C5D4",
                    },
                    splitLine: {
                        lineStyle: {
                            color: ["#344B64"],
                            type: "dashed",
                            width: 2,
                        },
                    },
                },
                grid: {
                    left: 20,
                    right: 15,
                    top: 50,
                    bottom: 7,
                    containLabel: true,
                },
                series: [
                    {
                        name: "大型",
                        type: "bar",
                        stack: "one",
                        barWidth: 12,
                        data: chartData.seriesData_01,
                        showBackground: true,
                        backgroundStyle: {
                            color: "rgba(187,230,245,.3)",
                        }
                    },
                    {
                        name: "中型",
                        type: "bar",
                        stack: "one",
                        data: chartData.seriesData_02,
                    },
                    {
                        name: "小型",
                        type: "bar",
                        stack: "one",
                        data: chartData.seriesData_03
                    },
                ],
            }
 
            this.myChart.setOption(option)
        },
 
    },
}
</script>
 
<style lang="scss" scoped>
.echarts-box {
    width: 100%;
    height: 213px;
}
</style>