Your Name
2022-05-20 2dbec630c2e618606f5625ca08e261ee0caba60f
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
<template>
    <el-dialog title="各部门风险分析单元" :visible.sync="chartsVisible" :modal-append-to-body="false" :close-on-click-modal="false" width="600px">
        <div id="departmentChart" style="width:90%;height:360px;margin: 0 auto;">
        </div>
    </el-dialog>
</template>
 
<script>
    import {getDepartmentChart} from "../../../../../api/riskLevelManage";
 
    export default {
        name: "departmentChart",
        data() {
            return {
                numData:[],
                departmentData:[],
                myChart:'',
                chartsVisible:false,
            }
        },
        mounted() {
 
        },
        methods : {
            show(){
                this.chartsVisible = true
                this.getChart()
            },
            async getChart() {
                let res = await getDepartmentChart()
                if(res.data.code === '200') {
                    debugger
                    this.numData = res.data.result.map(item =>{
                        return item["count"]
                    })
                    this.departmentData = res.data.result.map(item =>{
                        return item.department
                    })
                    this.myChart = this.$echarts.init(document.getElementById('departmentChart'))
                    this.myChart.setOption({
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            top: '5%',
                            left: 'center',
                            orient:'vertical'
                        },
                        xAxis: {
                            type: 'category',
                            data: this.departmentData
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                data: this.numData,
                                type: 'bar',
                                itemStyle: {
                                    normal: {
                                        color: function(params) {
                                            // 给出颜⾊组
                                            var colorList = ['#fac858','#5470c6','#91cc75','#fac858','#ee6666','#73c0de','#fc8452','#3ba272','#9a60b4','#ea7ccc'];
                                            return colorList[params.dataIndex]
                                        },
                                    }
                                },
                                showBackground: true,
                                backgroundStyle: {
                                    color: '#5470c6'
                                }
                            }]
                    })
                }else{
                    this.$message({
                        type:'warning',
                        message:res.data.message
                    })
                }
 
            },
        }
    }
</script>
 
<style scoped>
 
</style>