ggfwjsc/src/view/echarts_hygiene/pie2.vue

224 lines
4.9 KiB
Vue
Raw Normal View History

2024-04-17 14:20:33 +08:00
<template>
2024-05-23 16:39:28 +08:00
<div ref="chart" style="width: 100%; height: 260px"></div>
2024-04-17 14:20:33 +08:00
</template>
2024-07-11 10:46:45 +08:00
<script setup>
2024-05-13 10:53:21 +08:00
import { onMounted, reactive, ref, onBeforeMount, defineProps } from "vue";
2024-04-17 14:20:33 +08:00
// 局部引入echarts核心模块
import * as echarts from "echarts";
2024-05-13 10:53:21 +08:00
const props = defineProps({
list: {
type: Array,
default: () => [],
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
year: {
type: Array,
default: () => [],
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
});
const data = reactive({
list: [],
zgffje: [], //职工医疗保险发放人次
cxffje: [], //城乡医疗保险发放人次
year: [],
option: {},
bg: [],
});
const chart = ref(); // 创建DOM引用
2024-04-17 14:20:33 +08:00
2024-05-13 10:53:21 +08:00
const getOption = () => {
data.option = {
tooltip: {
trigger: "axis",
padding: [20, 10, 20, 10],
formatter: "{b0}<br />{a1}:{c1} <br />{a2}:{c2} ",
},
legend: {
data: ["职工医疗保险金额", "城乡医疗保险金额"],
2024-05-23 16:39:28 +08:00
top: "3%",
right: "25%",
2024-04-17 14:20:33 +08:00
textStyle: {
2024-05-22 15:04:24 +08:00
fontSize: 16,
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-17 14:20:33 +08:00
},
},
2024-05-13 10:53:21 +08:00
grid: {
2024-05-23 16:39:28 +08:00
top: "25%",
2024-05-13 10:53:21 +08:00
left: "1%",
2024-05-23 16:39:28 +08:00
right: "5%",
bottom: "0%",
2024-05-13 10:53:21 +08:00
containLabel: true,
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
xAxis: {
type: "category",
// boundaryGap: false,
data: data.year,
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-05-22 15:04:24 +08:00
fontSize: 16,
2024-05-13 10:53:21 +08:00
color: "#ffffff",
},
2024-04-17 14:20:33 +08:00
},
},
2024-05-23 16:39:28 +08:00
yAxis: [
{
name: "职工医疗保险金额",
type: "value",
nameTextStyle: {
// 设置Y轴名称的样式
fontSize: 14, // 这里设置字体大小为20
},
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
fontSize: 16,
color: "#ffffff",
},
},
axisLine: {
//y轴线的颜色以及宽度
show: false,
lineStyle: {
color: "#ffffff",
fontSize: 16,
width: 1,
type: "solid",
},
2024-05-13 10:53:21 +08:00
},
2024-04-17 14:20:33 +08:00
},
2024-05-23 16:39:28 +08:00
{
name: "城乡医疗保险金额",
type: "value",
min: 0, // 设置Y轴最小值
max: function (value) {
// 自定义Y轴最大值确保数据点显示在顶部
return Math.ceil(Math.max(value.max, value.max * 1.5) / 50) * 50;
},
splitLine: {
show: false,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
nameTextStyle: {
// 设置Y轴名称的样式
fontSize: 14, // 这里设置字体大小为20
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
fontSize: 16,
color: "#ffffff",
},
},
axisLine: {
//y轴线的颜色以及宽度
show: false,
lineStyle: {
color: "#ffffff",
fontSize: 16,
width: 1,
type: "solid",
},
2024-05-13 10:53:21 +08:00
},
2024-04-17 14:20:33 +08:00
},
2024-05-23 16:39:28 +08:00
],
2024-05-13 10:53:21 +08:00
series: [
{
name: "背景",
type: "bar",
data: data.bg,
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
{
2024-05-23 16:39:28 +08:00
yAxisIndex: 0,
2024-05-13 10:53:21 +08:00
name: "职工医疗保险金额",
type: "line",
symbol: "emptyCircle",
2024-04-17 14:20:33 +08:00
2024-05-13 10:53:21 +08:00
symbolSize: 10,
itemStyle: {
borderColor: "#00FCFF",
borderWidth: 1,
color: "#00FCFF",
},
2024-05-23 16:39:28 +08:00
label: {
show: true,
color: "#ffffff",
position: "top",
formatter: function (data) {
return data.value;
},
},
2024-05-13 10:53:21 +08:00
data: data.zgffje,
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
{
2024-05-23 16:39:28 +08:00
yAxisIndex: 1,
2024-05-13 10:53:21 +08:00
name: "城乡医疗保险金额",
type: "line",
symbol: "emptyCircle",
2024-04-17 14:20:33 +08:00
2024-05-13 10:53:21 +08:00
symbolSize: 10,
itemStyle: {
borderColor: "#2468FF",
borderWidth: 1,
color: "#2468FF",
},
2024-05-23 16:39:28 +08:00
label: {
show: true,
color: "#ffffff",
position: "bottom",
formatter: function (data) {
return data.value;
},
},
2024-05-13 10:53:21 +08:00
data: data.cxffje,
},
],
};
};
const setChart = () => {
2024-04-17 14:20:33 +08:00
var myChart = echarts.init(chart.value);
2024-05-13 10:53:21 +08:00
myChart.setOption(data.option);
};
2024-07-11 10:46:45 +08:00
const setChart1 = () => {
data.zgffje = [];
data.cxffje = [];
data.bg = [];
data.list.forEach((item) => {
data.zgffje.push(item.zgffje);
data.cxffje.push(item.cxffje);
data.bg.push("");
});
};
2024-04-17 14:20:33 +08:00
2024-05-13 10:53:21 +08:00
onBeforeMount(() => {
setTimeout(() => {
data.list = props.list;
data.year = props.year;
2024-07-11 10:46:45 +08:00
if (data.list.length !== 0) {
// console.log("城乡医疗保险金额", data.list, data.year);
setChart1();
getOption();
setChart();
}
2024-05-13 10:53:21 +08:00
}, 600);
2024-04-17 14:20:33 +08:00
});
</script>
2024-07-11 10:46:45 +08:00
<style scoped></style>