pie.vue
3.23 KB
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
<template>
<div>
<div id="pieChart" :style="styleInner"></div>
</div>
</template>
<script>
// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts');
// 引入柱状图
require('echarts/lib/chart/pie');
// 引入提示框和标题组件
require('echarts/lib/component/tooltip');
require('echarts/lib/component/title');
require("echarts/lib/component/legendScroll");
export default {
name: 'pieChart',
data () {
return {
}
},
props:{
optionsInner: {
type: Object,
default:() => {
return {}
}
},
styleInner: {
type: Object,
default:() => {
return {width: '1000px', height: '500px'}
}
},
},
watch:{
optionsInner:{
handler(newVal,oldVal){
console.log(newVal,'-------------------------------pie newval')
console.log(oldVal,'-------------------------------pie oldVal')
this.drawLine(newVal)
},
deep:true,
}
},
mounted(){
this.drawLine();
},
methods: {
drawLine(data){
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('pieChart'),'light');
// 绘制图表
myChart.setOption(this.optionsFunc(data));
window.addEventListener('resize',function(){
myChart.resize()
})
},
optionsFunc(data){
if(data&&data.series){
var seriesData = data.series[0].data
var amount = data.title.subtext
var legendData = data.legend.data
var legendFormat = data.legend.formatter
}else{
var seriesData = []
var amount = 0
var legendData = []
var legendFormat = ''
}
return {
title: {
text:'业务量',
textAlign: 'center',
textVerticalAlign: 'center',
subtext: amount,
itemGap:25,
textStyle:{
fontSize:16,
color:'#97a8be',
},
subtextStyle:{
fontSize:24,
color:'#000'
},
left: '29.5%',
top: '40%',
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)",
},
legend: {
type: 'scroll',
orient: 'vertical',
right: 20,
top:30,
itemWidth:20,
itemHeight:10,
itemGap:15,
textStyle:{
fontSize:16,
},
data:legendData,
formatter: legendFormat
},
series: [
{
name:'业务量',
type:'pie',
radius: ['55%', '70%'],
center: ['30%', '50%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: false,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data:seriesData
}
]
}
},
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>