wangyanshen
2023-01-11 28c552b1eb7942e03bec6ded2f9b36cf966eba5f
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
<template>
   <div class="pine-chart">
        <div :id="divid" class="pie-chart"></div>
   </div>
</template>
 
<script>
import * as echarts from 'echarts';
 
var chartDom;
var myChart;
var option;
export default {
    props:{
        divid:String,
        pinedata: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 = {
                title: {
                    text: this.title,
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    show:false
                },
                series: [
                    {
                    type: 'pie',
                    radius: '50%',
                    itemStyle: {
                        normal: {
                            borderWidth: 1, //扇区间加间隔
                            borderColor: '#ffffff', //间隔为白色
                            labelLine :{
                                show:true
                            },
                            color: function (colors) {
                                if(isCustomerColor){
                                    let colorList = [
                                    '#70b603',
                                    '#facd91',
                                    '#b8741a',
                                    '#d9001b',
                                    ];
                                    return colorList[colors.dataIndex];
                                }else {
                                    let colorList = [
                                        '#fc8251',
                                        '#5470c6',
                                        '#91cd77',
                                        '#ef6567',
                                    ];
                                    return colorList[colors.dataIndex];                                    
                                }
                            }
                        }
                    },
                    data: this.pinedata,
                    emphasis: {
                        itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                    }
                ]
        };
 
        option && myChart.setOption(option);
        }
    }
}
</script>
 
<style scoped>
.pine-chart{
    width: 100%;
    height: 100%;
}
.pie-chart{
    width: 100%;
    height: 100%;
}
</style>