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常用的修饰符的作用详解

    Vue常用的修饰符的作用详解

    为了方便大家写代码,Vue 给大家提供了很多方便的修饰符,比如我们经常用到的取消冒泡,阻止默认事件等等,这篇文章将给大家分享Vue 中的常用的修饰符
    2022-08-08
  • el-form表单el-form-item验证规则里prop一次验证两个或多个值问题

    el-form表单el-form-item验证规则里prop一次验证两个或多个值问题

    这篇文章主要介绍了el-form表单el-form-item验证规则里prop一次验证两个或多个值问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • vue使用SVG实现圆形进度条音乐播放

    vue使用SVG实现圆形进度条音乐播放

    这篇文章主要为大家详细介绍了vue使用SVG实现圆形进度条音乐播放,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-04-04
  • vue3中el-uplod结合ts实现图片粘贴上传

    vue3中el-uplod结合ts实现图片粘贴上传

    本文主要介绍了vue3中el-uplod结合ts实现图片粘贴上传,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-07-07
  • Vue-cli项目部署到Nginx服务器的方法

    Vue-cli项目部署到Nginx服务器的方法

    这篇文章主要介绍了Vue-cli项目部署到Nginx服务器的方法,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-11-11
  • Vue使用自定义指令实现页面底部加水印

    Vue使用自定义指令实现页面底部加水印

    本文主要实现给项目的整个背景加上自定义水印,可以改变水印的文案和字体颜色等,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-06-06
  • vue3如何监听页面的滚动

    vue3如何监听页面的滚动

    这篇文章主要给大家介绍了关于vue3如何监听页面的滚动的相关资料,在vue中实现滚动监听和原生js无太大差异,文中通过图文介绍的非常详细,需要的朋友可以参考下
    2023-07-07
  • vue项目初始化到登录login页面的示例

    vue项目初始化到登录login页面的示例

    今天小编就为大家分享一篇vue项目初始化到登录login页面的示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-10-10
  • Vue开发Html5微信公众号的步骤

    Vue开发Html5微信公众号的步骤

    这篇文章主要介绍了Vue开发Html5微信公众号的步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04
  • Vue实现点击按钮复制文本内容的例子

    Vue实现点击按钮复制文本内容的例子

    今天小编就为大家分享一篇Vue实现点击按钮复制文本内容的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-11-11

最新评论