ChartPie.vue
2.91 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
<script>
import * as echarts from 'echarts'
import { echartColors } from '@/utils/index'
import merge from 'lodash.merge'
export default {
// 饼图
name: 'ChartPie',
components: {},
props: {
// 图例
legend: {
type: Array,
default: () => ['新增客户'],
},
// 展示数据集
series: {
type: Array,
default: () => [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' },
],
},
// 自定义图表配置项,使用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.drawChart()
},
},
created() {},
mounted() {
this.drawChart()
},
methods: {
drawChart() {
// eslint-disable-next-line
this.myChart = echarts.init(this.$refs.chart)
let option = {
color: echartColors,
// title: {
// text: 'Stacked Area Chart',
// left: 'center',
// top: 'bottom'
// },
tooltip: {
trigger: 'item',
// textStyle: {
// color: '#FFF', // 设置文字颜色
// fontSize: 12,
// },
// backgroundColor: '#505050',
// borderWidth: 0,
// axisPointer: {
// type: 'cross',
// label: {
// backgroundColor: '#6a7985',
// },
// },
},
legend: {
x: 'center',
y: '88%',
// selectedMode: false,
type: 'scroll', // 分页类型
icon: 'circle',
itemWidth: 8,
itemHeight: 8,
tooltip: {
show: true,
},
textStyle: {
color: '#36363A',
fontSize: 12,
lineHeight: 14,
},
},
grid: {
left: '3%',
right: '3%',
bottom: '20px',
top: '30px',
containLabel: true,
},
series: {
type: 'pie',
radius: '50%',
data: this.series,
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 ref="chart" class="chart-pie chart"></div>
</template>
<style lang="scss" scoped>
.chart {
height: 100%;
min-width: 200px;
min-height: 200px;
}
</style>