This commit is contained in:
duanxiaohai 2024-07-13 17:07:07 +08:00
parent 2b752cf012
commit 56e5bc4441
2 changed files with 192 additions and 81 deletions

View File

@ -0,0 +1,155 @@
<template>
<div ref="chart" style="width: 100%; height: 300px"></div>
</template>
<script setup>
import { onBeforeMount, onMounted, reactive, ref } from "vue";
// echarts
import * as echarts from "echarts";
const chart = ref(); // DOM
const data = reactive({
list: [],
month: [],
option: {},
color: [
"rgba(255, 252, 166, 1)",
"rgba(128, 229, 229, 1)",
"rgba(246, 255, 103, 1)",
"rgba(82, 174, 255, 1)",
],
});
let datas = [
{
name: "高血压",
value: 200,
},
{
name: "糖尿病",
value: 230,
},
{
name: "其他疾病患者",
value: 198,
},
{
name: "无重大疾病患者",
value: 80,
},
];
const getOption = () => {
data.option = {
color: data.color,
title: {
//
// text: "", //
textStyle: {
//
color: "#fff",
fontSize: 16,
},
// left: "24%", //
// top: "38%", //
// subtext: `100%`, //
// subtextStyle: {
// //
// color: "#00FFFB",
// fontSize: 22,
// fontWeight: "bold",
// },
// textAlign: "center", //
},
// grid: {
// top: "13%",
// left: "1%",
// right: "1%",
// bottom: "0%",
// },
legend: {
itemHeight: 10,
itemWidth: 25,
icon: "rect",
orient: "vertical",
top: "center",
right: "16%",
itemGap: 20, //
textStyle: {
align: "left",
color: "#ffffff",
verticalAlign: "middle",
rich: {
name: {
width: 80,
fontSize: 16,
},
value: {
width: 30,
align: "right",
fontFamily: "Medium",
fontSize: 16,
},
rate: {
width: 20,
align: "right",
fontSize: 16,
},
},
},
data: datas,
formatter: (name) => {
if (datas.length) {
const item = datas.filter((item) => item.name === name)[0];
return `{name|${name}} {value| ${item.value}}`;
}
},
},
tooltip: {
trigger: "item",
formatter: "{b}:{d}",
},
calculable: true,
series: [
{
name: "",
type: "pie",
// radius: ["45%", "90%"],
// center: ["25%", "50%"],
roseType: "radiuas",
labelLine: {
normal: {
length: 30, // 线
length2: 70,
lineStyle: {
color: "white", // 线
},
},
},
label: {
show: true,
formatter: "{b}:{c}" + "个\n\n",
borderWidth: 10,
borderRadius: 4,
fontSize: 16,
padding: [0, -80],
},
data: datas,
},
],
};
};
const setChart = () => {
var myChart = echarts.init(chart.value);
myChart.setOption(data.option);
};
// 使
onBeforeMount(() => {
setTimeout(() => {
getOption();
setChart();
}, 600);
});
</script>
<style scoped></style>

View File

@ -37,104 +37,60 @@ let datas = [
value: 80, value: 80,
}, },
]; ];
const colorList = ["#ffd813", "#08daaa", "#6571fc"];
const getOption = () => { const getOption = () => {
data.option = { data.option = {
color: data.color, //
title: { title: {
// // text: "",
// text: "", //
textStyle: { textStyle: {
// color: "#212b43",
color: "#fff", fontSize: 14, //fontWeight: 'normal',
fontSize: 16,
}, },
// left: "24%", // }, //
// top: "38%", //
// subtext: `100%`, //
// subtextStyle: {
// //
// color: "#00FFFB",
// fontSize: 22,
// fontWeight: "bold",
// },
// textAlign: "center", //
},
// grid: {
// top: "13%",
// left: "1%",
// right: "1%",
// bottom: "0%",
// },
legend: { legend: {
itemHeight: 10, bottom: "0;",
itemWidth: 25,
icon: "rect",
orient: "vertical",
top: "center",
right: "16%",
itemGap: 30, //
textStyle: {
align: "left",
color: "#ffffff",
verticalAlign: "middle",
rich: {
name: {
width: 80,
fontSize: 16,
},
value: {
width: 30,
align: "right",
fontFamily: "Medium",
fontSize: 16,
},
rate: {
width: 20,
align: "right",
fontSize: 16,
},
},
},
data: datas,
formatter: (name) => {
if (datas.length) {
const item = datas.filter((item) => item.name === name)[0];
return `{name|${name}} {value| ${item.value}}`;
}
},
}, },
tooltip: { tooltip: {
trigger: "item", trigger: "item",
formatter: "{b}:{d}",
}, },
calculable: true,
series: [ series: [
{ {
name: "",
type: "pie", type: "pie",
// radius: ["45%", "90%"], radius: [0, 100],
// center: ["25%", "50%"], center: ["50%", "40%"],
roseType: "radiuas", roseType: "area",
labelLine: { itemStyle: {
normal: { color: (params) => {
length: 30, // 线 return colorList[params.dataIndex];
length2: 80,
lineStyle: {
color: "white", // 线
},
},
}, },
borderRadius: 8,
}, //
label: { label: {
show: true, show: true,
formatter: "{b}:{c}" + "个\n\n", position: "outside",
borderWidth: 10, formatter: "{a|{b}{d}%}\n{hr|}",
borderRadius: 4, rich: {
padding: [0, -80], hr: {
backgroundColor: "auto",
borderRadius: 3,
width: 1,
height: 3,
padding: [3, 3, 0, -12],
}, },
data: datas, a: {
padding: [0, 1, -20, 15],
color: "auto",
},
},
},
data: [
{ value: 200, name: "高血压" },
{ value: 230, name: "糖尿病" },
{ value: 198, name: "其他疾病患者" },
{ value: 80, name: "无重大疾病患者" },
],
}, },
], ],
}; };