ggfwjsc/src/view/echarts_hygiene/pie.vue

194 lines
4.0 KiB
Vue
Raw Normal View History

2024-04-17 14:20:33 +08:00
<template>
2024-05-13 10:53:21 +08:00
<div ref="chart" style="width: 100%; height: 250px"></div>
2024-04-17 14:20:33 +08:00
</template>
<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: () => [],
},
year: {
type: Array,
default: () => [],
},
});
const data = reactive({
list: [],
zgffrc: [], //职工医疗保险发放人次
cxffrc: [], //城乡医疗保险发放人次
year: [],
option: {},
bg:[],
});
2024-04-17 14:20:33 +08:00
const chart = ref(); // 创建DOM引用
2024-05-13 10:53:21 +08:00
const getOption = () => {
data.option = {
tooltip: {
trigger: "axis",
formatter: "{b0}<br />{a0}:{c0} <br />{a1}:{c1} ",
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
legend: {
top: "6%",
right: "11%",
textStyle: {
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-05-13 10:53:21 +08:00
color: "#ffffff",
2024-04-17 14:20:33 +08:00
},
},
2024-05-13 10:53:21 +08:00
grid: {
top: "23%",
left: "1%",
right: "10%",
bottom: "0%",
containLabel: true,
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
calculable: true,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-05-13 10:53:21 +08:00
},
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
data: data.year,
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
{
axisTick: false,
type: "category",
data: data.year,
axisLabel: {
show: false,
2024-04-17 14:20:33 +08:00
},
},
2024-05-13 10:53:21 +08:00
],
yAxis: [
{
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-05-13 10:53:21 +08:00
},
2024-04-17 14:20:33 +08:00
},
},
2024-05-13 10:53:21 +08:00
{
type: "value",
min: 0,
max: 100,
splitLine: {
show: false,
lineStyle: {
type: "solid",
color: "rgb(221, 242, 255,0.1)",
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
},
axisLine: {
show: false,
lineStyle: {
type: "dotted",
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
},
axisLabel: {
show: false,
fontSize: 14,
fontFamily: "MicrosoftYaHei",
2024-05-21 15:56:26 +08:00
color: "#ffffff",
fontSize: 14,
2024-05-13 10:53:21 +08:00
lineHeight: 19,
},
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
],
series: [
{
name: "职工医疗保险发放人次",
type: "bar",
data: data.zgffrc,
barWidth: "18%",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "rgba(142, 187, 255, 1)",
},
{
offset: 1,
color: "rgba(142, 187, 255, 0.20)",
},
]),
},
2024-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
{
name: "城乡医疗保险发放人次",
type: "bar",
data: data.cxffrc,
barWidth: "18%",
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-04-17 14:20:33 +08:00
},
2024-05-13 10:53:21 +08:00
{
type: "bar",
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
color: "rgba(221, 242, 255, 0.1)",
},
data: data.bg.map(() => 100),
barWidth: 50,
},
],
};
2024-04-17 14:20:33 +08:00
};
2024-05-13 10:53:21 +08:00
const setChart = () => {
2024-04-17 14:20:33 +08:00
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
2024-05-13 10:53:21 +08:00
myChart.setOption(data.option);
};
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;
data.list.forEach((item) => {
data.zgffrc.push(item.zgffrc);
data.cxffrc.push(item.cxffrc);
data.bg.push("");
})
getOption();
setChart();
}, 600);
2024-04-17 14:20:33 +08:00
});
</script>
<style scoped>
</style>