ggfwjsc/src/view/echarts/eP3_2.vue

126 lines
2.6 KiB
Vue
Raw Normal View History

2024-04-15 13:33:05 +08:00
<template>
2024-04-15 14:11:14 +08:00
<div ref="chart" style="width: 100%; height: 200px"></div>
2024-04-15 13:33:05 +08:00
</template>
<script setup >
import { onMounted, reactive, ref } from "vue";
// 局部引入echarts核心模块
import * as echarts from "echarts";
const chart = ref(); // 创建DOM引用
let option = {
tooltip: {
trigger: "axis",
},
legend: {
top: "8%",
right: "5%",
textStyle: {
fontSize: 12,
color: "#ccc",
},
},
grid: {
left: "1%",
right: "4%",
bottom: "3%",
containLabel: true,
},
calculable: true,
xAxis: [
{
type: "category",
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ccc",
},
},
data: ["2019", "2020", "2021", "2022", "2023"],
},
],
yAxis: [
{
type: "value",
splitLine: {
show: true,
lineStyle: {
color: "rgba(226, 226, 226, 0.3)",
width: 1,
},
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#ccc",
},
},
},
],
series: [
{
2024-04-15 14:11:14 +08:00
name: "特困发放人次",
2024-04-15 13:33:05 +08:00
type: "bar",
data: [2.0, 4.9, 7.0, 23.2, 25.6],
showBackground: true,
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)",
},
]),
},
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
{
2024-04-15 14:11:14 +08:00
name: "低保发放人次",
2024-04-15 13:33:05 +08:00
type: "bar",
data: [2.6, 5.9, 9.0, 26.4, 28.7],
showBackground: true,
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)",
},
]),
},
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
],
};
// 使用生命钩子
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>