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
| <template>
| <!-- 年龄比例 -->
| <div class="echarts">
| <ECharts :option="option" :resize="false" />
| </div>
| </template>
|
| <script setup lang="ts">
| import ECharts from "@/components/ECharts/index.vue";
| import { ECOption } from "@/components/ECharts/config";
|
| interface ChartProp {
| value: number;
| name: string;
| percentage: string;
| }
|
| let data: ChartProp[] = [
| { value: 200, name: "10岁以下", percentage: "16%" },
| { value: 110, name: "10 - 18岁", percentage: "8%" },
| { value: 150, name: "18 - 30岁", percentage: "12%" },
| { value: 310, name: "30 - 40岁", percentage: "24%" },
| { value: 250, name: "40 - 60岁", percentage: "20%" },
| { value: 260, name: "60岁以上", percentage: "20%" }
| ];
|
| const colors = ["#F6C95C", "#EF7D33", "#1F9393", "#184EA1", "#81C8EF", "#9270CA"];
|
| const option: ECOption = {
| color: colors,
| tooltip: {
| show: true,
| trigger: "item",
| formatter: "{b} <br/>占比:{d}%"
| },
| legend: {
| orient: "vertical",
| right: "20px",
| top: "15px",
| itemGap: 15,
| itemWidth: 14,
| formatter: function (name: string) {
| let text = "";
| data.forEach((val: ChartProp) => {
| if (val.name === name) text = " " + name + " " + val.percentage;
| });
| return text;
| },
| textStyle: { color: "#fff" }
| },
| grid: { top: "bottom", left: 10, bottom: 10 },
| series: [
| {
| zlevel: 1,
| name: "年龄比例",
| type: "pie",
| selectedMode: "single",
| radius: [50, 90],
| center: ["35%", "50%"],
| startAngle: 60,
| label: {
| position: "inside",
| show: true,
| color: "#fff",
| formatter: function (params) {
| return (params.data as ChartProp).percentage;
| },
| rich: {
| b: {
| fontSize: 16,
| lineHeight: 30,
| color: "#fff"
| }
| }
| },
| itemStyle: {
| shadowColor: "rgba(0, 0, 0, 0.2)",
| shadowBlur: 10
| },
| data: data.map((val: ChartProp, index: number) => {
| return {
| value: val.value,
| name: val.name,
| percentage: val.percentage,
| itemStyle: {
| borderWidth: 10,
| shadowBlur: 20,
| borderColor: colors[index],
| borderRadius: 10
| }
| };
| })
| },
| {
| name: "",
| type: "pie",
| selectedMode: "single",
| radius: [50, 90],
| center: ["35%", "50%"],
| startAngle: 60,
| data: [
| {
| value: 1000,
| name: "",
| label: {
| show: true,
| formatter: "{a|本日总数}",
| rich: {
| a: {
| align: "center",
| color: "rgb(98,137,169)",
| fontSize: 14
| }
| },
| position: "center"
| }
| }
| ]
| }
| ]
| };
| </script>
| <style lang="scss" scoped>
| .echarts {
| width: 100%;
| height: 100%;
| }
| </style>
|
|