ggfwjsc/src/view/echarts_yl/eP2.vue

160 lines
2.7 KiB
Vue
Raw Normal View History

2024-04-15 09:15:31 +08:00
<template>
2024-04-18 11:07:22 +08:00
<div ref="chart" style="width: 100%;height:250px;"></div>
2024-04-15 09:15:31 +08:00
</template>
<script setup >
2024-05-11 16:51:39 +08:00
import { onBeforeMount, reactive, ref } from "vue";
2024-04-15 09:15:31 +08:00
// 局部引入echarts核心模块
import * as echarts from "echarts";
const chart = ref(); // 创建DOM引用
2024-05-11 16:51:39 +08:00
const props = defineProps({
list1: {
type: Array,
default: () => {
return [];
},
},
list2: {
type: Array,
default: () => {
return [];
},
},
year: {
type: Array,
default: () => {
return [];
},
},
});
const data = reactive({
list1: [],
list2: [],
year: [],
2024-05-13 11:03:34 +08:00
option: {},
bg:[],
2024-05-11 16:51:39 +08:00
})
const getOption = () => {
data.option = {
2024-04-15 09:15:31 +08:00
tooltip: {
trigger: "axis",
2024-04-15 15:19:07 +08:00
padding: [20, 10, 20, 10],
2024-05-11 16:51:39 +08:00
formatter: "{b0}<br />{a1}:{c1} <br />{a2}:{c2}",
2024-04-15 09:15:31 +08:00
},
legend: {
2024-05-11 16:51:39 +08:00
data: [ "90-98补贴人次", "99以上补贴人次"],
2024-04-15 13:33:05 +08:00
top: "8%",
right: "15%",
textStyle: {
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-15 13:33:05 +08:00
},
2024-04-15 09:15:31 +08:00
},
grid: {
2024-04-15 13:33:05 +08:00
left: "1%",
2024-04-15 14:11:14 +08:00
right: "10%",
2024-04-15 09:15:31 +08:00
bottom: "3%",
containLabel: true,
},
xAxis: {
type: "category",
2024-05-11 16:51:39 +08:00
data: data.year,
2024-04-15 13:33:05 +08:00
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-04-15 13:33:05 +08:00
},
},
2024-04-15 09:15:31 +08:00
},
yAxis: {
type: "value",
2024-04-15 13:33:05 +08:00
splitLine: {
show: true,
lineStyle: {
2024-05-21 15:56:26 +08:00
color: "rgba(255, 255, 255, 0.2)",
fontSize: 14,
2024-04-15 13:33:05 +08:00
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-05-21 15:56:26 +08:00
fontSize: 14,
2024-04-15 13:33:05 +08:00
},
},
2024-04-15 09:15:31 +08:00
},
series: [
2024-04-15 15:19:07 +08:00
{
name: "背景",
type: "bar",
2024-05-13 11:03:34 +08:00
data: data.bg,
2024-04-15 15:19:07 +08:00
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
2024-04-15 09:15:31 +08:00
{
name: "90-98补贴人次",
type: "line",
2024-04-15 13:33:05 +08:00
symbol: "emptyCircle",
symbolSize: 10,
itemStyle: {
borderColor: "#E8FF00",
borderWidth: 1,
color: "#E8FF00",
},
2024-05-11 16:51:39 +08:00
data: data.list1,
2024-04-15 09:15:31 +08:00
},
{
name: "99以上补贴人次",
type: "line",
2024-04-15 13:33:05 +08:00
symbol: "emptyCircle",
symbolSize: 10,
itemStyle: {
borderColor: "#2468FF",
borderWidth: 1,
color: "#2468FF",
},
2024-05-11 16:51:39 +08:00
data: data.list2,
2024-04-15 09:15:31 +08:00
},
],
};
2024-05-11 16:51:39 +08:00
}
2024-04-15 09:15:31 +08:00
2024-05-11 16:51:39 +08:00
const setChart = () => {
2024-04-15 09:15:31 +08:00
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
2024-05-11 16:51:39 +08:00
myChart.setOption(data.option);
}
2024-04-15 09:15:31 +08:00
2024-05-11 16:51:39 +08:00
// 使用生命钩子
// 使用生命钩子
onBeforeMount(() => {
setTimeout(() => {
data.list1 = props.list1
data.list2 = props.list2
data.year = props.year
2024-05-13 11:03:34 +08:00
data.year.forEach(()=>{
data.bg.push(0)
})
2024-05-11 16:51:39 +08:00
getOption()
setChart()
}, 600)
2024-04-15 09:15:31 +08:00
});
</script>
<style scoped>
</style>