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
<template>
    <div class="container">
        <div class="chart" ref="buildingCost_ref"></div>
    </div>
</template>
 
<script>
export default {
    data () {
        return {
            chartInstance: null,
            data: [
                {
                    building: '通讯楼',
                    cost: '9.75'
                },
                {
                    building: '学生公寓',
                    cost: 7.36
                },
                {
                    building: '外语楼',
                    cost: 4.95
                },
                {
                    building: '2号餐厅',
                    cost: 6.04
                },
                {
                    building: '1号餐厅',
                    cost: 6.89
                },
                {
                    building: '实验楼',
                    cost: 5.28
                },
                {
                    building: '教学楼',
                    cost: 12.60
                },
            ]
        }
    },
    mounted () {
        this.initChart()
        this.updateChart()
    },
    methods: {
        //初始化chart
        initChart () {
            this.chartInstance = this.$echarts.init(this.$refs.buildingCost_ref)
        },
        getData () {
 
        },
        //格式化数据并配置chart
        updateChart () {
            this.data.sort((a, b) => {
                return a.cost - b.cost
            })
            const buildings = this.data.map((item => {
                return item.building
            }))
            const cost = this.data.map((item) => {
                return item.cost
            })
            const option = {
                title: {
                    show: true,
                    text: ['{a|▎}', '{b|学校建筑用电排名}'],
                    left: 16,
                    top: 16,
                    textStyle: {
                        rich: {
                            a: {
                                color: '#28f2ff',
                                fontSize: 16,
                                weight: 400
                            },
                            b: {
                                color: '#fff',
                                fontSize: 16,
                                weight: 400
                            }
                        }
                    }
                },
                tooltop: {
                    trigger: 'item',
                    formatter: '{c}%'
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    splitLine: {
                        show: false
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#206489'
                        }
                    },
                    axisLabel: {
                        show: false
                    },
                },
                yAxis: {
                    type: 'category',
                    data: buildings,
                    axisLine: {
                        lineStyle: {
                            color: '#206489'
                        }
                    },
                    axisLabel: {
                        color: '#E9F2F3',
                    },
                },
                series: [
                    {
                        name: '用电占比',
                        type: 'bar',
                        showBackground: true,
                        label: {
                            position: 'right',
                            show: true,
                            color: '#fff',
                        },
                        data: cost,
                        barWidth: '14px',
                        itemStyle: {
                            normal: {
                                // borderRadius: [0, 7, 7, 0],
                                // color: this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                //     offset: 0,
                                //     color: '#03132E'
                                // }, {
                                //     offset: 1,
                                //     color: '#F8BE42'
                                // }]),
                            }
                        },
 
                    }
                ]
            }
            this.chartInstance.setOption(option)
        }
    }
}
</script>
 
<style lang="scss" scoped>
.container {
    width: 400px;
    height: 100%;
    background: url(/zhjg/img/home/juxing2.png) no-repeat;
    background-size: 100% 100%;
    .chart {
        width: 100%;
        height: 100%;
    }
}
</style>