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
| <template>
| <div class="chart-wrapper" ref="sourcePie"></div>
| </template>
|
| <script>
| import resize from '@/mixins/resize';
| const echarts = require('echarts');
| export default {
| name: 'sourcePie',
| props: {
| chartData: {
| type: Object
| },
| titleechart: {
| type: String,
| default: ''
| },
| colors: {
| type: String,
| default: '#636972'
| }
| },
| mixins: [resize],
| data() {
| return {};
| },
| mounted() {
| this.initEchart();
| },
| methods: {
| initEchart() {
| var colorList = ['#569ada', '#f47b2a', '#a1a1a1', '#ffc61f', '#3a6cc6', '#6cae3f', '#1e5c94'];
| // 基于准备好的dom,初始化echarts实例
| let seriesData = [];
| if (this.chartData.data) {
| this.chartData.data.forEach(element => {
| seriesData.push({
| name: element.name,
| value: element.data
| });
| });
| }
| this.myChart = echarts.init(this.$refs.sourcePie);
| this.myChart.setOption(
| {
| title: {
| show: true, //显示策略,默认值true,可选为:true(显示) | false(隐藏)
| text: this.titleechart, //主标题文本,'\n'指定换行
| x: 'center', //水平安放位置,默认为'left',可选为:'center' | 'left' | 'right' | {number}(x坐标,单位px)
| y: '2%', //垂直安放位置,默认为top,可选为:'top' | 'bottom' | 'center' | {number}(y坐标,单位px)
| textAlign: null, //水平对齐方式,默认根据x设置自动调整,可选为: left' | 'right' | 'center
| textStyle: {
| //主标题文本样式{"fontSize": 18,"fontWeight": "bolder",}
| color: this.colors,
| fontWeight: 'normal',
| fontSize: 50
| }
| },
|
| tooltip: {
| trigger: 'item',
| borderWidth: 1,
| padding: 5,
| formatter: function (parms) {
| var str = parms.marker + '' + parms.data.name + '</br>' + '占比:' + parms.percent + '%';
| return str;
| }
| },
| legend: [
| {
| type: 'plain',
| bottom: '12%',
| itemGap: 20,
| textStyle: {
| fontSize: 24,
| color: this.colors
| },
| data: this.chartData.legend
| }
| ],
| series: [
| {
| type: 'pie',
| center: ['50%', '40%'],
| radius: ['35%', '50%'],
| label: {
| show: true,
| position: 'outside',
| textStyle: {
| fontSize: 28,
| color: this.colors
| }
| },
| labelLine: {
| show: true,
| normal: {
| length: 20,
| length2: 30,
| lineStyle: {
| width: 1
| }
| }
| },
| data: seriesData
| }
| ]
| },
| true
| );
| }
| },
| watch: {
| chartData: {
| handler() {
| this.initEchart();
| },
| deep: true
| }
| }
| };
| </script>
|
|