Vue3 Echarts通用的折线图带阴影效果实现

 更新时间:2024年07月04日 14:38:31   作者:陈琦鹏  
在环保仓管项目中,做了一个每月对药品、消耗品、设备的进出,进行统计百分比,效果好看,后面经常在用这个样式,下面通过示例代码分享Vue3 Echarts通用的折线图带阴影效果实现,感兴趣的朋友一起看看吧

在环保仓管项目中,做了一个每月对药品、消耗品、设备的进出,进行统计百分比,效果好看,后面经常在用这个样式,以下是详细分析:

下载Echarts

//npm
npm install echarts --save
//淘宝镜像cnpm(安装速度快)
cnpm install echarts --save
//yarn
yarn add echarts

代码示例

<template>
    <div id="echartsThree" style="width: 100%;height: 100%;"></div>
</template>
<script setup>
    import * as echarts from 'echarts';
    import { onMounted,ref } from 'vue';
    onMounted(()=>{
        getEcharts();
    })
    const getEcharts = () => {
        let chartDom = document.getElementById("echartsThree");
        let myChart = echarts.init(chartDom);
        let rq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
        let seriesArr = []
        let list = [{
      		name: "药品",
      		children: [100, 100, 100, 100, 80, 90, 100, 88, 88, 99, 100, 80]
      	},
      	{
      		name: "消耗品",
      		children: [50, 50, 40, 40, 35, 40, 30, 35, 30, 30, 25, 25]
      	},
      	{
      		name: "设备",
      		children: [75, 75, 55, 55, 45, 50, 40, 30, 35, 40, 50, 50]
      	}
      ]
      let colorArr = ["0, 62, 246", "0, 193, 142", "253, 148, 67"]
      list.forEach((val, index) => {
      	seriesArr.push({
      		name: val.name,
      		type: 'line',
      		symbolSize: 6,
      		data: val.children,
      		areaStyle: {
      			normal: {
      				color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
      					offset: 0,
      					color: `rgba(${colorArr[index]},.2)`
      				}, {
      					offset: 1,
      					color: 'rgba(255, 255, 255,0)'
      				}], false)
      			}
      		},
      		itemStyle: {
      			normal: {
      				color: `rgb(${colorArr[index]})`
      			}
      		},
      		lineStyle: {
      			normal: {
      				width: 2,
      				shadowColor: `rgba(${colorArr[index]}, .2)`,
      				shadowBlur: 4,
      				shadowOffsetY: 25
      			}
      		}
      	})
      })
      let option = {
      	backgroundColor: "#fff",
      	tooltip: {
      		trigger: 'axis',
      		axisPointer: {
      			lineStyle: {
      				color: '#ddd'
      			}
      		},
      		backgroundColor: 'rgba(255,255,255,1)',
      		padding: [5, 10],
      		textStyle: {
      			color: '#000',
      		}
      	},
      	legend: {
      		right: "center",
      		top: "6%",
      		textStyle: {
      			color: '#000',
      			fontSize: 12,
      			fontWeight: 600
      		},
      		data: list.map(val => {
      			return val.name
      		})
      	},
      	grid: {
      		left: '2%',
      		right: '5%',
      		bottom: '6%',
      		top: '18%',
      		containLabel: true
      	},
      	xAxis: {
      		type: 'category',
      		data: rq,
      		boundaryGap: false,
      		splitLine: {
      			show: true,
      			interval: 'auto',
      			lineStyle: {
      				type: "dashed",
      				color: ['#cfcfcf']
      			}
      		},
      		axisTick: {
      			show: false
      		},
      		axisLine: {
      			lineStyle: {
      				color: '#cfcfcf'
      			}
      		},
      		axisLabel: {
      			// margin: 10,
      			textStyle: {
      				fontSize: 12,
      				color: "#9e9d9f",
      				fontWeight: 600
      			}
      		}
      	},
      	yAxis: [{
      		name: "(%)",
      		type: 'value',
      		splitLine: {
      			show: true,
      			lineStyle: {
      				type: "dashed",
      				color: ['#cfcfcf']
      			}
      		},
      		axisTick: {
      			show: false
      		},
      		axisLine: {
      			show: true,
      			lineStyle: {
      				fontSize: 12,
      				color: '#cfcfcf',
      			}
      		},
      		axisLabel: {
      			textStyle: {
      				fontSize: 12,
      				color: "#9e9d9f",
      				fontWeight: 600
      			}
      		},
      		max: 100
      	}],
      	series: seriesArr
      };
        myChart.setOption(option);
    }
</script>

运行结果

到此这篇关于Vue3 Echarts通用的折线图带阴影的文章就介绍到这了,更多相关vue3 echarts折线图内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue中的v-show,v-if,v-bind的使用示例详解

    vue中的v-show,v-if,v-bind的使用示例详解

    这篇文章主要介绍了vue中的v-show,v-if,v-bind的使用,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • 使用 Vue 绑定单个或多个 Class 名的实例代码

    使用 Vue 绑定单个或多个 Class 名的实例代码

    这篇文章主要介绍了使用 Vue 绑定单个或多个 Class 名的实例代码,非常不错,具有参考借鉴价值,需要的朋友参考下吧
    2018-01-01
  • vue3.0实现点击切换验证码(组件)及校验

    vue3.0实现点击切换验证码(组件)及校验

    这篇文章主要为大家详细介绍了vue3.0实现点击切换验证码(组件)及校验,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-11-11
  • 详解Vue里循环form表单项实例

    详解Vue里循环form表单项实例

    本文主要介绍了Vue里循环form表单项实例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-09-09
  • 如何在 vue3 中使用高德地图

    如何在 vue3 中使用高德地图

    这篇文章主要介绍了如何在 vue3 中使用高德地图,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧
    2024-08-08
  • Vue2中使用自定义指令实现el-table虚拟列表的代码示例

    Vue2中使用自定义指令实现el-table虚拟列表的代码示例

    在实际开发中,我们可能会面临其他需求,例如在 el-table 中无法使用分页技术的情况下展示海量数据,这种情况下,页面可能会出现卡顿,严重时甚至可能引发浏览器崩溃,所以针对这个问题本文给大家介绍了vue2中使用自定义指令实现el-table虚拟列表,需要的朋友可以参考下
    2025-01-01
  • vue实现数字动态翻牌的效果(开箱即用)

    vue实现数字动态翻牌的效果(开箱即用)

    这篇文章主要介绍了vue实现数字动态翻牌的效果(开箱即用),实现原理是激将1到9的数字竖直排版,通过translate移动位置显示不同数字,本文通过实例代码讲解,需要的朋友可以参考下
    2019-12-12
  • vue脚手架中配置Sass的方法

    vue脚手架中配置Sass的方法

    本篇文章主要介绍了vue脚手架中配置Sass的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-01-01
  • vue自定义上传头像组件功能

    vue自定义上传头像组件功能

    这篇文章主要介绍了vue自定义上传头像组件功能,介绍了与一般上传组件的区别,通过实例代码介绍了上传图片组件的方法,需要的朋友可以参考下
    2024-01-01
  • vue router嵌套路由在history模式下刷新无法渲染页面问题的解决方法

    vue router嵌套路由在history模式下刷新无法渲染页面问题的解决方法

    这篇文章主要介绍了vue router嵌套路由在history模式下刷新无法渲染页面问题的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-01-01

最新评论