ggfwjsc/src/view/echarts_hygiene/tnb.vue

154 lines
3.1 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-05-13 10:53:21 +08:00
import { onMounted, reactive, ref,onBeforeMount,defineProps } 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: () => [],
},
year:{
type: Array,
default: () => [],
}
});
const data= reactive({
list:[],
year:[],
option:{},
bg:[],
})
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-04-19 15:55:36 +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,
},
xAxis: {
type: "category",
// boundaryGap: false,
2024-05-13 10:53:21 +08:00
data: data.year,
2024-04-19 15:55:36 +08:00
// splitArea: {
// show: true,
// interval: '10',
// areaStyle: {
// color: ["rgba(255, 255, 255, 0.10)"],
// width:10,
// },
// },
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-19 15:55:36 +08:00
},
},
},
yAxis: {
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-19 15:55:36 +08:00
},
},
},
series: [
{
name: "背景",
type: "bar",
2024-05-13 10:53:21 +08:00
data: data.bg,
2024-04-19 15:55:36 +08:00
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
{
name: "糖尿病人数",
type: "line",
stack: "Total",
symbol: "emptyCircle",
symbolSize: 10,
itemStyle: {
borderColor: "#E8FF00",
borderWidth: 1,
color: "#E8FF00",
},
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-05-13 10:53:21 +08:00
data: data.list,
2024-04-19 15:55:36 +08:00
},
],
};
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-04-19 15:55:36 +08:00
2024-05-13 10:53:21 +08:00
onBeforeMount(() => {
setTimeout(() => {
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
});
2024-05-13 10:53:21 +08:00
2024-04-19 15:55:36 +08:00
</script>
<style scoped>
</style>