tanghaolin
2023-01-11 50ad0a40d942624f7fcdfa8af3bc67d656a747a3
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
<template>
   <div class="bar-chart-box">
        <div :id="divid" class="bar-chart"></div>
        <div class="number-tag">
            <div class="flex">
                <div class="flex-direction"><div class="number-ball color1">10</div>设备故障诊断</div>
            </div>
            <div class="flex space-evenly align-items">
                <div class="flex-direction"><div class="number-ball color2">15</div>时序趋势预警</div>
                <div class="flex-direction"><div class="number-ball color3">7</div>专家趋势预警</div>
            </div>
        </div>
   </div>
</template>
 
<script>
import * as echarts from 'echarts';
 
var chartDom;
var myChart;
var option;
export default {
    props:{
        divid:String,
        bardata:Array,
        title:String,
        iscoustomecolor:Boolean
    },
    data(){
        return {
 
        }
    },
    mounted(){
        this.$nextTick(function(){
          setTimeout(() => {
            this.initPinChart()
        }, 100);
        })
 
    },
    methods:{
        initPinChart(){
            let isCustomerColor = this.iscoustomecolor
            chartDom = document.getElementById(this.divid);
            myChart = echarts.init(chartDom);
            option = option = {
                title: {
                    text: this.title,
                    left: 'center'
                },
                xAxis: {
                    type: 'category',
                    data: ['正常', '注意', '异常', '严重']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                    data: this.bardata,
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            //这里是颜色
                            color: function(params) {
                                //注意,如果颜色太少的话,后面颜色不会自动循环,最好多定义几个颜色
                                var colorList = [                                        
                                    '#70b603',
                                    '#facd91',
                                    '#b8741a',
                                    '#d9001b',
                                        ];
                                return colorList[params.dataIndex]
                            }
                        }
                    }
                    }
                ]
                };
 
        option && myChart.setOption(option);
        }
    }
}
</script>
 
<style scoped>
.bar-chart-box{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.bar-chart{
    width: 50%;
    height: 100%;
}
.number-tag{
    width: 50%;
    height: 100%;
}
.flex {
    width: 100%;
    height: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.space-evenly{
    justify-content: space-evenly;
}
.align-items{
    align-items: flex-start;
}
.number-ball{
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border:1px solid #000000;
    font-size:24px;
    color: #fff;
    font-weight: bold;
    text-align: center;
    line-height: 60px;
}
.flex-direction{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.color1{
    background-color: #F59A23;
}
.color2{
    background-color: #8080FF;
}
.color3{
    background-color: #EC808D;
}
</style>