jxdnsong
2022-10-25 bf5ba56e8a82f0ef699f2eae413d0dc2c4e4f67d
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
    <div class="container">
        <div class="chart" ref="SchoolCostCompare"></div>
    </div>
</template>
 
<script>
export default {
    data () {
        return {
            chartInstance: null,
            data: [
                {
                    mouth: '1月',
                    costIn2018: 15000,
                    costIn2019: 15000,
                },
                {
                    mouth: '2月',
                    costIn2018: 20000,
                    costIn2019: 25000,
                },
                {
                    mouth: '3月',
                    costIn2018: 15000,
                    costIn2019: 18000,
                },
                {
                    mouth: '4月',
                    costIn2018: 29000,
                    costIn2019: 28000,
                },
                {
                    mouth: '5月',
                    costIn2018: 37000,
                    costIn2019: 34000,
                },
                {
                    mouth: '6月',
                    costIn2018: 33000,
                    costIn2019: 30000,
                },
                {
                    mouth: '7月',
                    costIn2018: 45000,
                    costIn2019: 47000,
                },
                {
                    mouth: '8月',
                    costIn2018: 48500,
                    costIn2019: 49000,
                },
                {
                    mouth: '9月',
                    costIn2018: 38000,
                    costIn2019: 39000,
                },
                {
                    mouth: '10月',
                    costIn2018: 28000,
                    costIn2019: 30000,
                },
                {
                    mouth: '11月',
                    costIn2018: 20000,
                    costIn2019: 21500,
                },
                {
                    mouth: '12月',
                    costIn2018: 16000,
                    costIn2019: 16000,
                },
 
            ]
        }
    },
    mounted () {
        this.initChart()
        this.updateChart()
    },
    methods: {
        initChart () {
            this.chartInstance = this.$echarts.init(this.$refs.SchoolCostCompare)
        },
        updateChart () {
            const mouth = this.data.map(item => {
                return item.mouth
            })
            const costIn2018 = this.data.map(item => {
                return item.costIn2018
            })
            const costIn2019 = this.data.map(item => {
                return item.costIn2019
            })
            const option = {
                title: {
                    show: true,
                    text: ['{a|▎}', '{b|学校用电同比}'],
                    left: 16,
                    top: 16,
                    textStyle: {
                        rich: {
                            a: {
                                color: '#28f2ff',
                                fontSize: 16,
                            },
                            b: {
                                color: '#fff',
                                fontSize: 16,
                            }
                        }
                    }
                },
                grid: {
                    top: '35%',
                    left: '1%',
                    right: '2%',
                    bottom: '3%',
                    containLabel: true
                },
                legend: {
                    top: '16%',
                    textStyle: {
                        color: '#fff',
                    }
                },
                xAxis: {
                    type: 'category',
                    data: mouth,
                    axisLabel: {
                        textStyle: {
                            show: true,
                            color: "#fff",
                        },
                    }
 
 
                },
                yAxis: {
                    type: 'value',
                    name: 'KW·H',
                    nameTextStyle: {
                        color: "#fff",
                        padding: [-80, 0, 0, -50]
                    },
                    axisLabel: {
                        textStyle: {
                            show: true,
                            color: "#fff",
                        },
                    }
                },
                series: [
                    {
                        name: '2018年用电量',
                        type: 'bar',
                        barWidth: 10,
                        data: costIn2018,
                        itemStyle: {
                            normal: {
                                // color: this.$echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                                //     offset: 0,
                                //     color: '#001541'
                                // }, {
                                //     offset: 1,
                                //     color: '#28F2FF'
                                // }]),
                            }
                        },
 
                    },
                    {
                        name: '2019年用电量',
                        type: 'line',
                        data: costIn2019,
                        itemStyle: {
                            color: '#F8BE42',
                        }
                    },
                ]
            }
            this.chartInstance.setOption(option)
        }
    },
 
}
</script>
 
<style lang="scss" scoped>
.container {
    position: relative;
    width: 400px;
    height: 100%;
    background: url(/zhjg/img/home/juxing2.png);
    background-size: 100% 100%;
    .chart {
        width: 100%;
        height: 100%;
    }
}
</style>