ggfwjsc/src/view/echarts_work/eP4.vue

280 lines
5.7 KiB
Vue
Raw Normal View History

2024-04-18 14:52:07 +08:00
<template>
<div ref="chart" style="width: 100%; height: 360px"></div>
</template>
<script setup>
import { onMounted, reactive, ref } from "vue";
// 局部引入echarts核心模块
import * as echarts from "echarts";
const chart = ref(); // 创建DOM引用
const data = [120, 200, 50, 80, 70];
const data2 = [12, 20, 5, 8, 7];
const lineData = [150, 230, 24, 218, 135];
const lineData2 = [15, 23, 4, 18, 15];
const max = data
.concat(lineData)
.reduce((pre, cur) => (pre > cur ? pre : cur), 0); //找到这个新数组中的最大值
// 背景颜色
const color = [
{
type: "linear",
x: 0,
x2: 0,
y: 0,
y2: 1,
},
];
const option = {
tooltip: {
trigger: "axis",
2024-05-13 16:08:48 +08:00
formatter: "{b0}<br/> {a0}:{c0}<br/>{a1}:{c1}<br/>{a2}:{c2}<br/>{a3}:{c3}",
2024-04-18 14:52:07 +08:00
},
legend: {
data: [
"困难残疾人生活补贴人数",
"护理补贴人数",
"",
"困难残疾人生活补贴金额",
"护理补贴金额",
],
top: "3%",
textStyle: {
fontSize: 12,
color: "#ffffff", //上文字标题颜色
},
},
grid: {
top: "25%",
left: "6%",
right: "9%",
bottom: "5%",
containLabel: true,
color: "#ffffff",
},
calculable: true,
color,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ffffff",
},
},
axisTick: {
show: false, // 设置轴刻度不显示
},
data: ["2019", "2020", "2021", "2022", "2023"],
},
{
type: "category",
show: false,
data: ["2019", "2020", "2021", "2022", "2023"],
},
],
yAxis: [
{
type: "value",
scale: true,
name: "补贴人数",
2024-05-13 16:08:48 +08:00
2024-04-18 14:52:07 +08:00
splitLine: {
//分割线配置
show: false,
lineStyle: {
color: "#ffffff",
width: 1,
},
},
axisLabel: {
//y轴文字的配置
textStyle: {
color: "#ffffff",
},
},
axisLine: {
//y轴线的颜色以及宽度
show: false,
lineStyle: {
color: "#ffffff",
width: 1,
type: "solid",
},
},
},
{
type: "value",
scale: true,
min: 0,
2024-05-13 16:08:48 +08:00
2024-04-18 14:52:07 +08:00
name: "救助金额/元",
splitLine: {
show: false,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//y轴文字的配置
textStyle: {
color: "#ffffff",
},
},
axisLine: {
//y轴线的颜色以及宽度
show: false,
lineStyle: {
color: "#ffffff",
width: 1,
type: "solid",
},
},
},
{
2024-05-13 16:08:48 +08:00
type: "value",
min: 0,
max: 100,
splitLine: {
show: false,
lineStyle: {
type: "solid",
color: "rgb(221, 242, 255,0.1)",
},
2024-04-18 14:52:07 +08:00
},
2024-05-13 16:08:48 +08:00
axisLine: {
show: false,
lineStyle: {
type: "dotted",
},
},
axisLabel: {
show: false,
fontSize: 14,
fontFamily: "MicrosoftYaHei",
color: "#DEF1FF",
lineHeight: 19,
2024-04-18 14:52:07 +08:00
},
},
2024-05-13 16:08:48 +08:00
],
series: [
2024-04-18 14:52:07 +08:00
{
2024-05-13 16:08:48 +08:00
yAxisIndex: 0,
2024-04-18 14:52:07 +08:00
name: "困难残疾人生活补贴人数",
data: data,
barWidth: 10,
type: "bar",
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-05-13 16:08:48 +08:00
2024-04-18 14:52:07 +08:00
{
2024-05-13 16:08:48 +08:00
yAxisIndex: 0,
2024-04-18 14:52:07 +08:00
name: "护理补贴人数",
data: data2,
barWidth: 10,
type: "bar",
itemStyle: {
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-05-13 16:08:48 +08:00
yAxisIndex: 1,
name: "困难残疾人生活补贴金额",
data: lineData,
type: "line", //线状图
itemStyle: {
borderColor: "#00FCFF",
borderWidth: 1,
color: "#00FCFF",
},
},
{
yAxisIndex: 1,
name: "护理补贴金额",
data: lineData2,
type: "line", //线状图
itemStyle: {
borderColor: "#00FCFF",
borderWidth: 1,
color: "#2468FF",
},
},
{
yAxisIndex: 2,
2024-04-18 14:52:07 +08:00
xAxisIndex: 1,
itemStyle: {
color: "rgba(180, 180, 180, 0.2)", //外阴影背景
},
2024-05-13 16:08:48 +08:00
data: data.map(() => 100),
2024-04-18 14:52:07 +08:00
barWidth: 60, //外阴影背景宽
emphasis: {
itemStyle: {
color: {
type: "linear",
x: 0,
x2: 0,
y: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "rgba(64, 247, 176, 0.25)",
},
{
offset: 1,
color: "rgba(17, 34, 64, 0.25)",
},
],
},
},
},
type: "bar",
},
],
};
// 使用生命钩子
onMounted(() => {
// 基于准备好的dom初始化echarts实例
// var myChart = echarts.init(document.getElementById('main'));
// Vue3中 需要引入
var myChart = echarts.init(chart.value);
// init(); // vue3.2没有this
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
// 单图表响应式: 跟随浏览器大小改变
// window.addEventListener("resize", () => {
// myChart.resize();
// });
});
</script>
<style scoped></style>