2024-04-15 09:15:31 +08:00
|
|
|
|
<template>
|
2024-05-23 11:05:35 +08:00
|
|
|
|
<div ref="chart" style="width: 100%; height: 285px"></div>
|
2024-04-15 09:15:31 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup >
|
2024-05-23 11:05:35 +08:00
|
|
|
|
import { onBeforeMount, reactive, ref, defineProps } from "vue";
|
2024-04-15 09:15:31 +08:00
|
|
|
|
// 局部引入echarts核心模块
|
|
|
|
|
import * as echarts from "echarts";
|
|
|
|
|
|
|
|
|
|
const chart = ref(); // 创建DOM引用
|
|
|
|
|
|
2024-05-13 09:42:06 +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: {},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
bg: [],
|
|
|
|
|
});
|
2024-05-13 09:42:06 +08:00
|
|
|
|
|
2024-05-23 11:05:35 +08:00
|
|
|
|
const getOption = () => {
|
2024-05-13 09:42:06 +08:00
|
|
|
|
data.option = {
|
2024-05-23 11:05:35 +08:00
|
|
|
|
tooltip: {
|
|
|
|
|
trigger: "axis",
|
|
|
|
|
padding: [20, 10, 20, 10],
|
|
|
|
|
formatter: "{b0}<br />{a1}:{c1} <br />{a2}:{c2} ",
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
legend: {
|
|
|
|
|
data: ["特困发放人次", "低保发放人次"],
|
|
|
|
|
top: "5%",
|
|
|
|
|
right: "28%",
|
2024-04-15 13:33:05 +08:00
|
|
|
|
textStyle: {
|
2024-05-22 15:04:24 +08:00
|
|
|
|
fontSize: 16,
|
2024-05-23 11:05:35 +08:00
|
|
|
|
color: "#ffffff",
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
grid: {
|
2024-05-23 16:39:28 +08:00
|
|
|
|
top: "25%",
|
2024-05-23 11:05:35 +08:00
|
|
|
|
left: "1%",
|
|
|
|
|
right: "10%",
|
|
|
|
|
bottom: "3%",
|
|
|
|
|
containLabel: true,
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: "category",
|
|
|
|
|
// boundaryGap: false,
|
|
|
|
|
data: data.year,
|
|
|
|
|
axisLabel: {
|
|
|
|
|
//坐标轴刻度标签的相关设置
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
},
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
yAxis: [
|
|
|
|
|
{
|
|
|
|
|
name: "特困发放人次",
|
|
|
|
|
type: "value",
|
2024-05-23 16:39:28 +08:00
|
|
|
|
min: 0, // 设置Y轴最小值
|
|
|
|
|
max: function (value) {
|
|
|
|
|
// 自定义Y轴最大值,确保数据点显示在顶部
|
|
|
|
|
return Math.ceil(Math.max(value.max, value.max * 2) / 50) * 50;
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
nameTextStyle: {
|
|
|
|
|
// 设置Y轴名称的样式
|
|
|
|
|
fontSize: 14, // 这里设置字体大小为20
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: true,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: "rgba(255, 255, 255, 0.2)",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
width: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
//坐标轴刻度标签的相关设置
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
axisLine: {
|
|
|
|
|
//y轴线的颜色以及宽度
|
|
|
|
|
show: false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
width: 1,
|
|
|
|
|
type: "solid",
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-04-15 15:19:07 +08:00
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
{
|
|
|
|
|
name: "低保发放人次",
|
|
|
|
|
type: "value",
|
2024-05-23 16:39:28 +08:00
|
|
|
|
min: 0, // 设置Y轴最小值
|
|
|
|
|
max: function (value) {
|
|
|
|
|
// 自定义Y轴最大值,确保数据点显示在顶部
|
|
|
|
|
return Math.ceil(Math.max(value.max, value.max * 1.3) / 50) * 50;
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
nameTextStyle: {
|
|
|
|
|
// 设置Y轴名称的样式
|
|
|
|
|
fontSize: 14, // 这里设置字体大小为20
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: "rgba(255, 255, 255, 0.2)",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
width: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
//坐标轴刻度标签的相关设置
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
axisLine: {
|
|
|
|
|
//y轴线的颜色以及宽度
|
|
|
|
|
show: false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
width: 1,
|
|
|
|
|
type: "solid",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
name: "背景",
|
|
|
|
|
type: "bar",
|
|
|
|
|
data: data.bg,
|
|
|
|
|
showBackground: true,
|
|
|
|
|
backgroundStyle: {
|
|
|
|
|
color: "rgba(180, 180, 180, 0.2)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
yAxisIndex: 0,
|
|
|
|
|
name: "特困发放人次",
|
|
|
|
|
type: "line",
|
|
|
|
|
symbol: "emptyCircle",
|
2024-04-15 13:33:05 +08:00
|
|
|
|
|
2024-05-23 11:05:35 +08:00
|
|
|
|
symbolSize: 10,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
borderColor: "#00FCFF",
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
color: "#00FCFF",
|
|
|
|
|
},
|
2024-05-23 16:39:28 +08:00
|
|
|
|
label: {
|
|
|
|
|
show: true,
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
formatter: function (data) {
|
|
|
|
|
return data.value;
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
data: data.list1,
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
{
|
|
|
|
|
yAxisIndex: 1,
|
|
|
|
|
name: "低保发放人次",
|
|
|
|
|
type: "line",
|
|
|
|
|
symbol: "emptyCircle",
|
2024-04-15 09:15:31 +08:00
|
|
|
|
|
2024-05-23 11:05:35 +08:00
|
|
|
|
symbolSize: 10,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
borderColor: "#2468FF",
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
color: "#2468FF",
|
|
|
|
|
},
|
2024-05-23 16:39:28 +08:00
|
|
|
|
label: {
|
|
|
|
|
show: true,
|
|
|
|
|
color: "#ffffff",
|
|
|
|
|
formatter: function (data) {
|
|
|
|
|
return data.value;
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
data: data.list2,
|
2024-04-15 13:33:05 +08:00
|
|
|
|
},
|
2024-05-23 11:05:35 +08:00
|
|
|
|
],
|
|
|
|
|
};
|
2024-04-15 09:15:31 +08:00
|
|
|
|
};
|
2024-05-13 09:42:06 +08:00
|
|
|
|
const setChart = () => {
|
2024-04-15 09:15:31 +08:00
|
|
|
|
// Vue3中: 需要引入
|
|
|
|
|
var myChart = echarts.init(chart.value);
|
|
|
|
|
|
|
|
|
|
// 使用刚指定的配置项和数据显示图表。
|
2024-05-13 09:42:06 +08:00
|
|
|
|
myChart.setOption(data.option);
|
2024-05-23 11:05:35 +08:00
|
|
|
|
};
|
2024-04-15 09:15:31 +08:00
|
|
|
|
|
2024-05-13 09:42:06 +08:00
|
|
|
|
// 使用生命钩子
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
|
setTimeout(() => {
|
2024-05-23 11:05:35 +08:00
|
|
|
|
data.list1 = props.list1;
|
|
|
|
|
data.list2 = props.list2;
|
|
|
|
|
data.year = props.year;
|
|
|
|
|
data.year.forEach(() => {
|
|
|
|
|
data.bg.push(0);
|
|
|
|
|
});
|
|
|
|
|
getOption();
|
|
|
|
|
setChart();
|
|
|
|
|
}, 600);
|
2024-04-15 09:15:31 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
</style>
|