ggfwjsc/src/view/echarts_hygiene/pie3.vue

258 lines
5.9 KiB
Vue
Raw Normal View History

2024-07-11 16:57:39 +08:00
<template>
2024-07-12 11:50:43 +08:00
<div ref="chart" style="width: 100%; height: 280px"></div>
2024-07-11 16:57:39 +08:00
</template>
<script setup >
import { onMounted, reactive, ref, onBeforeMount, defineProps } from "vue";
// 局部引入echarts核心模块
import * as echarts from "echarts";
const props = defineProps({
list: {
type: Array,
default: () => [],
},
year: {
type: Array,
default: () => [],
},
});
const data = reactive({
list: [],
2024-07-12 11:50:43 +08:00
zg: [3136,4345, 4964, 5846, 8076],
cx: [3860,6980, 7585, 8858, 12737],
year: [2019,2020, 2021, 2022, 2023],
2024-07-11 16:57:39 +08:00
option: {},
2024-07-12 11:50:43 +08:00
bg: [0, 0, 0, 0, 0],
2024-07-11 16:57:39 +08:00
});
const chart = ref(); // 创建DOM引用
const getOption = () => {
data.option = {
tooltip: {
trigger: "axis",
2024-07-12 11:50:43 +08:00
formatter: "{b0}<br />{a1}:{c1} <br />{a3}:{c3}",
2024-07-11 16:57:39 +08:00
},
legend: {
2024-07-12 11:50:43 +08:00
data: ["职工医疗保险", "城乡医疗保险"],
2024-07-11 16:57:39 +08:00
top: "6%",
2024-07-12 11:50:43 +08:00
right: "5%",
2024-07-11 16:57:39 +08:00
textStyle: {
fontSize: 16,
color: "#ffffff",
},
},
grid: {
top: "23%",
left: "1%",
right: "10%",
2024-07-12 11:50:43 +08:00
bottom: "0%",
2024-07-11 16:57:39 +08:00
containLabel: true,
},
calculable: true,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
},
data: data.year,
},
{
axisTick: false,
type: "category",
data: data.year,
axisLabel: {
show: false,
},
},
],
yAxis: [
{
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
},
},
{
type: "value",
min: 0,
max: 100,
splitLine: {
show: false,
lineStyle: {
type: "solid",
color: "rgb(221, 242, 255,0.1)",
},
},
axisLine: {
2024-07-12 11:50:43 +08:00
show: false,
2024-07-11 16:57:39 +08:00
lineStyle: {
type: "dotted",
},
},
axisLabel: {
show: false,
fontSize: 16,
fontFamily: "MicrosoftYaHei",
color: "#ffffff",
lineHeight: 19,
},
},
],
series: [
{
z: 1,
name: "上部1",
type: "pictorialBar",
symbolPosition: "end",
2024-07-12 11:50:43 +08:00
data: data.zg,
2024-07-11 16:57:39 +08:00
symbol: "diamond",
2024-07-12 11:50:43 +08:00
symbolOffset: ["-65%", "-50%"],
2024-07-11 16:57:39 +08:00
symbolSize: [15, 10],
itemStyle: {
borderColor: "#2fffa4",
color: "rgba(142, 187, 255, 1)",
},
},
{
z: 1,
2024-07-12 11:50:43 +08:00
name: "职工医疗保险",
2024-07-11 16:57:39 +08:00
type: "bar",
barGap: 0.3 /*多个并排柱子设置柱子之间的间距*/,
2024-07-12 11:50:43 +08:00
data: data.zg,
2024-07-11 16:57:39 +08:00
barWidth: "30%",
label: {
show: true,
color: "#ffffff",
position: "top",
},
itemStyle: {
color: {
type: "linear",
x: 0,
x2: 1,
y: 0,
y2: 0,
colorStops: [
{ offset: 0, color: "rgba(142, 187, 255, .7)" },
{ offset: 0.5, color: "rgba(142, 187, 255, .7)" },
{ offset: 0.5, color: "rgba(142, 187, 255, .3)" },
{ offset: 1, color: "rgba(142, 187, 255, .5)" },
],
},
},
},
{
z: 2,
name: "上部1",
type: "pictorialBar",
symbolPosition: "end",
2024-07-12 11:50:43 +08:00
data: data.cx,
2024-07-11 16:57:39 +08:00
symbol: "diamond",
symbolOffset: ["62%", "-50%"],
symbolSize: [15, 10],
itemStyle: {
borderColor: "#32ffee",
color: "rgba(23, 237, 255, 1)",
},
},
{
z: 2,
2024-07-12 11:50:43 +08:00
name: "城乡医疗保险",
2024-07-11 16:57:39 +08:00
type: "bar",
barGap: 0.3 /*多个并排柱子设置柱子之间的间距*/,
2024-07-12 11:50:43 +08:00
data: data.cx,
2024-07-11 16:57:39 +08:00
barWidth: "30%",
label: {
show: true,
color: "#ffffff",
position: "top",
2024-07-12 11:50:43 +08:00
// formatter: function (data) {
// return data.value + "万";
// },
2024-07-11 16:57:39 +08:00
},
// itemStyle: {
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
// {
// offset: 0,
// color: "rgba(23, 237, 255, 1)",
// },
// {
// offset: 1,
// color: "rgba(23, 237, 255, 0.20)",
// },
// ]),
// },
2024-07-12 11:50:43 +08:00
itemStyle: {
2024-07-11 16:57:39 +08:00
color: {
type: "linear",
x: 0,
x2: 1,
y: 0,
y2: 0,
colorStops: [
{ offset: 0, color: "rgba(23, 237, 255, .7)" },
{ offset: 0.5, color: "rgba(23, 237, 255, .7)" },
{ offset: 0.5, color: "rgba(23, 237, 255, .3)" },
{ offset: 1, color: "rgba(23, 237, 255, .5)" },
],
},
},
},
{
type: "bar",
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
color: "rgba(221, 242, 255, 0.1)",
},
data: data.bg.map(() => 100),
barWidth: 40,
},
],
};
};
const setChart = () => {
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(data.option);
};
onBeforeMount(() => {
setTimeout(() => {
// data.list = props.list;
// data.year = props.year;
// data.list.forEach((item) => {
// data.zgffrc.push((item.zgffrc / 10000).toFixed(0));
// data.cxffrc.push((item.cxffrc / 10000).toFixed(0));
// // data.bg.push("");
// });
// console.log(data.zgffrc,data.cxffrc);
getOption();
setChart();
}, 600);
});
</script>
<style scoped>
</style>