ggfwjsc/src/view/echarts_hygiene/tnb.vue

184 lines
3.8 KiB
Vue
Raw Normal View History

2024-04-19 15:55:36 +08:00
<template>
<div ref="chart" style="width: 100%; height: 210px"></div>
</template>
<script setup >
2024-07-02 10:35:51 +08:00
import {
onMounted,
reactive,
ref,
onBeforeMount,
defineProps,
watch,
} from "vue";
2024-04-19 15:55:36 +08:00
// 局部引入echarts核心模块
import * as echarts from "echarts";
2024-05-13 10:53:21 +08:00
const props = defineProps({
list: {
type: Array,
default: () => [],
},
2024-07-02 10:35:51 +08:00
year: {
2024-05-13 10:53:21 +08:00
type: Array,
default: () => [],
2024-07-02 10:35:51 +08:00
},
});
const data = reactive({
list: [],
year: [],
option: {},
bg: [],
2024-05-13 10:53:21 +08:00
});
2024-04-19 15:55:36 +08:00
2024-05-13 10:53:21 +08:00
const chart = ref(); // 创建DOM引用
const getOption = () => {
data.option = {
2024-07-02 10:35:51 +08:00
tooltip: {
trigger: "axis",
padding: [20, 10, 20, 10],
formatter: "{b0}<br />{a1}:{c1} ",
},
grid: {
top: "5%",
left: "1%",
right: "10%",
bottom: "3%",
containLabel: true,
},
2024-04-19 15:55:36 +08:00
2024-07-02 10:35:51 +08:00
xAxis: {
type: "category",
// boundaryGap: false,
data: data.year,
// splitArea: {
// show: true,
// interval: '10',
// areaStyle: {
// color: ["rgba(255, 255, 255, 0.10)"],
// width:10,
// },
// },
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
2024-04-19 15:55:36 +08:00
},
},
2024-07-02 10:35:51 +08:00
yAxis: {
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
2024-04-19 15:55:36 +08:00
},
2024-07-02 10:35:51 +08:00
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
fontSize: 16,
},
2024-04-19 15:55:36 +08:00
},
},
2024-07-02 10:35:51 +08:00
series: [
{
name: "背景",
type: "bar",
data: data.bg,
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
2024-04-19 15:55:36 +08:00
},
2024-07-02 10:35:51 +08:00
{
name: "糖尿病人数",
type: "line",
stack: "Total",
symbol: "emptyCircle",
2024-04-19 15:55:36 +08:00
2024-07-02 10:35:51 +08:00
symbolSize: 10,
itemStyle: {
borderColor: "#E8FF00",
borderWidth: 1,
color: "#E8FF00",
},
label: {
2024-05-23 16:39:28 +08:00
show: true,
color: "#ffffff",
2024-07-02 10:35:51 +08:00
position: "top",
2024-05-23 16:39:28 +08:00
formatter: function (data) {
return data.value;
},
},
2024-07-02 10:35:51 +08:00
areaStyle: {
color: "#F4F65B",
normal: {
//线性渐变前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是true则该四个值是绝对像素位置。
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
// color: 'RGBA(184, 204, 241, 1)'
color: "rgba(255, 234, 90, 0.50)",
},
{
offset: 1,
color: "rgba(255, 234, 90, 0)",
},
],
false
),
shadowBlur: 0, //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
},
2024-04-19 15:55:36 +08:00
},
2024-07-02 10:35:51 +08:00
data: data.list,
2024-04-19 15:55:36 +08:00
},
2024-07-02 10:35:51 +08:00
],
};
2024-04-19 15:55:36 +08:00
};
2024-07-02 10:35:51 +08:00
watch(
() => props.list,
(newValue, oldValue) => {
setTimeout(() => {
data.list = props.list;
data.year = props.year;
data.year.forEach(() => {
data.bg.push(0);
});
getOption();
setChart();
}, 600);
}
);
2024-05-13 10:53:21 +08:00
const setChart = () => {
2024-04-19 15:55:36 +08:00
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
2024-05-13 10:53:21 +08:00
myChart.setOption(data.option);
2024-07-02 10:35:51 +08:00
};
2024-04-19 15:55:36 +08:00
2024-05-13 10:53:21 +08:00
onBeforeMount(() => {
setTimeout(() => {
2024-07-02 10:35:51 +08:00
data.list = props.list;
data.year = props.year;
data.year.forEach(() => {
data.bg.push(0);
});
getOption();
setChart();
}, 600);
2024-04-19 15:55:36 +08:00
});
</script>
<style scoped>
</style>