拖旺项目:聊城公交辅助决策系统
master
2022-04-27 493930a42a2ea3e13905ffd8772cdb945baa7bcf
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
<template>
  <div :id="id" :style="{width: width, height: height}"></div>
</template>
 
<script>
import * as echarts from "echarts";
export default {
  name: "charts",
  props: {
    //这里子组件需要接收父组件传递过来的参数
    id: {
      type: String,
      default:()=>'pie1'
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "200px",
    },
    option: {
      type: Array,
      default: [1,2,3,4,5],
    },
  },
  data() {
    return {
      chart: '',
      imgBg:require('../../assets/index/piebg.png')
    };
  },
  watch: {
    option: {
      handler(newVal, oldVal) {
        if(newVal && this.chart){
          this.chart.setOption(this.initOption());
        }
      },
      deep: true,
    },
  },
  created() {
  },
  mounted() {
    this.init();
  },
  methods: {
    initOption(){
      return  {
        tooltip: {
          trigger: 'item',
          show:false,
        },
        legend: {
          top: '5%',
          left: 'center',
          show:false,
        },
        color:['rgba(20,131,242,1)','rgba(2,254,211,1)','rgba(245,189,55,1)','rgba(107,194,252,1)','rgba(194,252,135,1)','rgba(255,255,255,1)'],
        graphic: {
          elements: [
            {
              type: 'image',
              style: {
                image: this.imgBg,
                width: 54,
                height: 54
              },
              left: 'center',
              top: 'center'
 
            }
          ]
        },
 
        series: [
          {
            name: 'Access From',
            type: 'pie',
            colorStops: [{
              offset: 0, color: 'red' // 0% 处的颜色
            }, {
              offset: 1, color: 'blue' // 100% 处的颜色
            }],
            radius: ['90%', '100%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: false,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
 
            itemStyle: {
              borderColor: '#1c1f24',
              borderWidth: 5,
            },
            labelLine: {
              show: false
            },
            data:  this.option
          },
          {
            name: 'Access From',
            type: 'pie',
            radius: ['55%', '80%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: false,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            itemStyle: {
              borderColor: '#1c1f24',
              borderWidth: 5
            },
            data: this.option
          }
        ]
      };
 
    },
    init() {
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption(this.initOption());
      window.addEventListener('resize', this.chart.resize)
    },
  },
};
</script>