ggfwjsc/src/view/echarts_yl/eP3_2.vue

198 lines
3.5 KiB
Vue
Raw Normal View History

2024-04-15 13:33:05 +08:00
<template>
2024-04-18 11:51:31 +08:00
<div ref="chart" style="width: 100%;height:280px;"></div>
2024-04-15 13:33:05 +08:00
</template>
<script setup >
2024-05-13 09:42:06 +08:00
import { onBeforeMount, reactive, ref,defineProps } from "vue";
2024-04-15 13:33:05 +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: [],
option: {}
})
const getOption = () =>{
data.option = {
2024-04-15 13:33:05 +08:00
tooltip: {
trigger: "axis",
2024-04-15 15:58:12 +08:00
formatter: "{b0}<br />{a0}:{c0} <br />{a1}:{c1} ",
2024-04-15 13:33:05 +08:00
},
legend: {
2024-04-16 10:15:19 +08:00
top: "5%",
2024-04-15 15:19:07 +08:00
right: "11%",
2024-04-15 13:33:05 +08:00
textStyle: {
fontSize: 12,
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-15 13:33:05 +08:00
},
},
grid: {
left: "1%",
2024-04-15 15:19:07 +08:00
right: "10%",
2024-04-16 10:15:19 +08:00
bottom: "5%",
2024-04-15 13:33:05 +08:00
containLabel: true,
},
calculable: true,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-15 13:33:05 +08:00
},
},
2024-05-13 09:42:06 +08:00
data: data.year,
2024-04-15 13:33:05 +08:00
},
2024-04-15 15:58:12 +08:00
{
axisTick: false,
type: "category",
2024-05-13 09:42:06 +08:00
data: data.year,
2024-04-15 15:58:12 +08:00
axisLabel: {
show: false,
},
},
2024-04-15 13:33:05 +08:00
],
2024-04-15 15:58:12 +08:00
2024-04-15 13:33:05 +08:00
yAxis: [
{
type: "value",
2024-04-15 15:58:12 +08:00
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
2024-04-15 13:33:05 +08:00
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
2024-04-25 16:28:11 +08:00
color: "#ffffff",
2024-04-15 13:33:05 +08:00
},
},
},
2024-04-15 15:58:12 +08:00
{
type: "value",
min: 0,
max: 100,
splitLine: {
show: false,
lineStyle: {
type: "solid",
color: "rgb(221, 242, 255,0.1)"
},
},
axisLine: {
show: false,
lineStyle: {
type: "dotted",
},
},
axisLabel: {
show: false,
fontSize: 14,
fontFamily: "MicrosoftYaHei",
color: "#DEF1FF",
lineHeight: 19,
},
},
2024-04-15 13:33:05 +08:00
],
series: [
{
2024-04-15 15:58:12 +08:00
name: "特困补助金额",
2024-04-15 13:33:05 +08:00
type: "bar",
2024-05-13 09:42:06 +08:00
data: data.list1,
2024-04-15 15:58:12 +08:00
barWidth: "18%",
2024-04-15 13:33:05 +08:00
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-15 15:58:12 +08:00
name: "低保补助金额",
2024-04-15 13:33:05 +08:00
type: "bar",
2024-05-13 09:42:06 +08:00
data: data.list2,
2024-04-15 15:58:12 +08:00
barWidth: "18%",
itemStyle: {
2024-04-15 13:33:05 +08:00
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-15 15:58:12 +08:00
},
{
type: "bar",
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
color: "rgba(221, 242, 255, 0.1)",
2024-04-15 13:33:05 +08:00
},
2024-04-15 15:58:12 +08:00
data: ["2019", "2020", "2021", "2022", "2023"].map(() => 100),
barWidth: 50,
2024-04-15 13:33:05 +08:00
},
],
};
2024-05-13 09:42:06 +08:00
}
const setChart = () => {
2024-04-15 13:33:05 +08:00
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// 使用刚指定的配置项和数据显示图表。
2024-05-13 09:42:06 +08:00
myChart.setOption(data.option);
}
2024-04-15 13:33:05 +08:00
2024-05-13 09:42:06 +08:00
// 使用生命钩子
onBeforeMount(() => {
setTimeout(() => {
data.list1 = props.list1
data.list2 = props.list2
data.year = props.year
getOption()
setChart()
}, 600)
2024-04-15 13:33:05 +08:00
});
</script>
<style scoped>
</style>