|
@@ -1,4 +1,4 @@
|
|
-<!-- 柱状图 -->
|
|
|
|
|
|
+<!-- 圆饼图 -->
|
|
<template>
|
|
<template>
|
|
<div :id="id" :class="className" :style="{ height, width }" />
|
|
<div :id="id" :class="className" :style="{ height, width }" />
|
|
</template>
|
|
</template>
|
|
@@ -10,87 +10,69 @@ const props = defineProps({
|
|
id: {
|
|
id: {
|
|
type: String,
|
|
type: String,
|
|
default: "pieChart",
|
|
default: "pieChart",
|
|
|
|
+ required: true,
|
|
},
|
|
},
|
|
className: {
|
|
className: {
|
|
type: String,
|
|
type: String,
|
|
- default: "",
|
|
|
|
|
|
+ default: "chart",
|
|
},
|
|
},
|
|
width: {
|
|
width: {
|
|
type: String,
|
|
type: String,
|
|
default: "400px",
|
|
default: "400px",
|
|
- required: true,
|
|
|
|
},
|
|
},
|
|
height: {
|
|
height: {
|
|
type: String,
|
|
type: String,
|
|
default: "400px",
|
|
default: "400px",
|
|
- required: true,
|
|
|
|
},
|
|
},
|
|
title: {
|
|
title: {
|
|
type: String,
|
|
type: String,
|
|
default: "",
|
|
default: "",
|
|
},
|
|
},
|
|
- percentData: {
|
|
|
|
- type: String,
|
|
|
|
- default: "0,0,0,0,0",
|
|
|
|
- },
|
|
|
|
- numberData: {
|
|
|
|
|
|
+ data: {
|
|
type: String,
|
|
type: String,
|
|
- default: "0,0,0,0,0",
|
|
|
|
|
|
+ default: "1,0,0,0,0",
|
|
|
|
+ required: true,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
+function getDataValue(i): number {
|
|
|
|
+ return props.data?.split(",")[i];
|
|
|
|
+}
|
|
const options = {
|
|
const options = {
|
|
- tooltip: {
|
|
|
|
- trigger: "item",
|
|
|
|
- formatter: "{a} \r\n {b}: {c} ({d}%)",
|
|
|
|
|
|
+ title: {
|
|
|
|
+ text: props.title,
|
|
|
|
+ left: "39%",
|
|
|
|
+ top: "52%",
|
|
|
|
+ textStyle: {
|
|
|
|
+ fontSize: 16,
|
|
|
|
+ fontWeight: "normal",
|
|
|
|
+ color: "#09132e",
|
|
|
|
+ },
|
|
},
|
|
},
|
|
legend: {
|
|
legend: {
|
|
- orient: "vertical",
|
|
|
|
- right: "10%",
|
|
|
|
- top: "5%",
|
|
|
|
|
|
+ right: "6%",
|
|
|
|
+ top: "6%",
|
|
|
|
+ padding: 0,
|
|
|
|
+ itemGap: 5,
|
|
|
|
+ icon: "roundRect",
|
|
data: ["0-20", "21-40", "41-60", "61-80", "81-100"],
|
|
data: ["0-20", "21-40", "41-60", "61-80", "81-100"],
|
|
},
|
|
},
|
|
series: [
|
|
series: [
|
|
{
|
|
{
|
|
- name: "访问来源",
|
|
|
|
|
|
+ name: props.title,
|
|
type: "pie",
|
|
type: "pie",
|
|
- radius: ["40%", "70%"],
|
|
|
|
|
|
+ radius: ["40%", "60%"],
|
|
avoidLabelOverlap: false,
|
|
avoidLabelOverlap: false,
|
|
label: {
|
|
label: {
|
|
- show: false,
|
|
|
|
- position: "center",
|
|
|
|
- },
|
|
|
|
- right: "40%",
|
|
|
|
- emphasis: {
|
|
|
|
- label: {
|
|
|
|
- show: true,
|
|
|
|
- fontSize: "30",
|
|
|
|
- fontWeight: "bold",
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- labelLine: {
|
|
|
|
show: true,
|
|
show: true,
|
|
|
|
+ formatter: "{c}%",
|
|
},
|
|
},
|
|
|
|
+ center: ["50%", "55%"],
|
|
data: [
|
|
data: [
|
|
- {
|
|
|
|
- value: 20,
|
|
|
|
- name: "A",
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- value: 12,
|
|
|
|
- name: "B",
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- value: 18,
|
|
|
|
- name: "C",
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- value: 20,
|
|
|
|
- name: "D",
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- value: 20,
|
|
|
|
- name: "E",
|
|
|
|
- },
|
|
|
|
|
|
+ { value: getDataValue(0), name: "0-20" },
|
|
|
|
+ { value: getDataValue(1), name: "21-40" },
|
|
|
|
+ { value: getDataValue(2), name: "41-60" },
|
|
|
|
+ { value: getDataValue(3), name: "61-80" },
|
|
|
|
+ { value: getDataValue(4), name: "81-100" },
|
|
],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
],
|
|
@@ -99,7 +81,7 @@ const options = {
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
// 图表初始化
|
|
// 图表初始化
|
|
const chart = echarts.init(
|
|
const chart = echarts.init(
|
|
- document.getElementById(props.id) as HTMLDivElement
|
|
|
|
|
|
+ document.getElementById(<string>props.id) as HTMLDivElement
|
|
);
|
|
);
|
|
chart.setOption(options);
|
|
chart.setOption(options);
|
|
// 大小自适应
|
|
// 大小自适应
|