PieChart.vue
2.51 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
<script>
import * as echarts from 'echarts'
import { echartColors } from '@/utils/index'
import merge from 'lodash.merge'
export default {
// 折线图
name: 'ChartLine',
components: {},
props: {
Data: {
type: Object,
default: null,
},
series: {
type: Array,
default: () => [120, 132, 101, 134, 90, 230, 210],
},
// 自定义图表配置项,使用loadsh.merge(origin, option)和原有的配置进行覆盖合并
// loadsh.merge: https://www.html.cn/doc/lodash/#_mergeobject-sources
option: {
type: Object,
default: null,
},
},
data() {
return {}
},
computed: {},
watch: {
series() {
this.$nextTick(() => {
this.drawChart()
})
},
},
created() {},
mounted() {
this.drawChart()
},
methods: {
drawChart() {
console.log('this.Data', this.Data)
this.myChart = echarts.init(this.$refs.chart)
let option
let series = []
let dateLe = []
// for(let i=0;this.Data.data.length;i++){
// }
option = {
legend: [
{
data: this.Data.optionss,
x: 'center',
y: 'bottom',
},
],
tooltip: {
trigger: 'item',
},
series: [
{
type: 'pie',
radius: '50%',
data: this.Data.data,
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
normal: {
label: {
show: true,
formatter: '{d}%',
},
labelLine: { show: true },
},
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
},
],
}
this.option && merge(option, this.option)
option && this.myChart.setOption(option)
new ResizeObserver((entries) => {
this.myChart.resize()
}).observe(this.$refs.chart)
},
},
}
</script>
<template>
<div v-if="series && series.length" ref="chart" class="chart-line chart" key="1"></div>
<div v-else class="chart-line chart" key="2"><div class="cc">暂无数据</div></div>
</template>
<style lang="scss" scoped>
.chart {
position: relative;
height: 100%;
min-width: 400px;
min-height: 400px;
}
</style>