在 vue2 中实现 echarts 立体方形柱状图及立体圆柱

本文主要是介绍在 vue2 中实现 echarts 立体方形柱状图及立体圆柱,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、在做大屏项目时,为了页面不显得单调,有时设计会设计些立体的柱状图,前几天做大屏刚好遇到,记录一下。echarts本身没有配置直接配置立体图,立体图实质是三个图形合并堆积形成的视觉效果,分别是上面的盖,中间主体和下面的底,再配合中间主体的渐变颜色而实现。本文默认都是使用过echarts的,常规项不赘述,只看option的配置项,先上效果。

2、立体方块图 

   pdChartOption(){let yList = [55,69,48,20,71]let xData = ['20240901','20240902','20240903','20240904','20240905'];let y2List = [20,15,10,18,16]let yAndy2 = [75,84,58,38,87]let indexList = [1,3]let that = thislet color = ["#CC1CAA","#8D67FF","#00FFFF","#48DE13","#FFC516","#DC3E14","#8E16F8",];let dom = 300;let barWidth = 25; //设置柱子宽度let colors = [];colors.push({type: "linear",x: 0,x2: 1,y: 0,y2: 0,colorStops: [{offset: 0,color: "#608efa", // 最上边},{offset: 0.5,color: "#5886f7", // 中间过渡},{offset: 0.5,color: "#5886f7cc", // 中间过渡},{offset: 1,color: "#2656f4", //下边},],});colors.push({type: "linear",x: 0,x2: 1,y: 0,y2: 0,colorStops: [{offset: 0,color: "#fe8686", // 最上边},{offset: 0.5,color: "#fe5858", // 中间过渡},{offset: 0.5,color: "#fe5858cc", // 中间过渡},{offset: 1,color: "#fe0b0c", //下边},],});colors.push({type: "linear",x: 0,x2: 1,y: 0,y2: 0,colorStops: [{offset: 0,color: "#3ace5f", // 最上边},{offset: 0.5,color: "#22b146", // 中间过渡},{offset: 0.5,color: "#22b146cc", // 中间过渡},{offset: 1,color: "#1aa83e", //下边},],});let option = {// backgroundColor: "#010d3a", //背景颜色//提示框tooltip: {trigger: "axis",formatter: function (params) {let count = 0indexList.forEach( e => {if (params[0].dataIndex == e) {count ++} }) //用来判断%数值的正负,显示红色还是绿色,下同,此处是判断显示提示框的 ‘+’‘-’号return `<div style="display:flex;"><div style="margin-right:.3125rem;">${params[0].name} : </div><div>${params[0].value} </br>${count > 0 ? '-':''} ${params[1].value}%</div></div>`},axisPointer: {//坐标轴指示器,坐标轴触发有效type: "shadow", // 默认为直线,可选为:'line' | 'shadow'},},/**区域位置*/grid: {left: "10%",right: "5%",top: "10%",bottom: "18%",},//X轴xAxis: {data: xData,type: "category",axisLine: {show: false,lineStyle: {color: "rgba(0,0,0,1)",shadowColor: "rgba(0,0,0,1)",shadowOffsetX: "20",},symbol: ["none", "arrow"],},splitLine: {show: false,},axisTick: {show: false,},axisLabel: {color: "#000",margin: 10, //x轴字离x轴的距离fontSize: 10,interval: 0, //使x轴文字显示全rotate: 0,},},yAxis: [{show: true,splitNumber: 4,axisLine: {show: false,},axisTick:{show:false,},splitLine: {show: true,lineStyle: {type: "dashed",color: "#a6d7ff",},},axisLabel: {color: "#000",margin: 10,fontSize: 12,},},{  type:'value',position: 'right',axisLabel: { //y轴设置为%show: false,interval: 'auto',formatter: '{value} %',},axisTick:{show:false,},axisLine: {show:false},splitLine: {show: false,lineStyle: {color:'#B7D0FF',type:'dashed'},},},],series: [{type: "bar",stack: 'pd',large: true,yAxisIndex: 0,barWidth: barWidth,showBackground: false, //显示柱子的背景颜色itemStyle: {normal: {color: function (params) {return colors[0];},},},label: {show: false,position: [-8, 0],color: "#6587f7",fontSize: 14,fontStyle: "bold",align: "center",},data: yList,},{type: "bar",stack: 'pd',large: true,yAxisIndex: 1,barWidth: barWidth,showBackground: false, //显示柱子的背景颜色itemStyle: {normal: {color: function (params) {let count = 0indexList.forEach( e => {if (params.dataIndex == e) {count ++} })if (count > 0 ) {return colors[2];} else {return colors[1];}},},},label: {show: true,position: [10, -20],//   color: "#fe090a",color:function (params) {let count = 0indexList.forEach( e => {if (params.dataIndex == e) {count ++} })if (count > 0 ) {return "#3ed565";} else {return "#fe090a";}},fontSize: 12,align: "center",formatter: function (params) {let count = 0indexList.forEach( e => {if (params.dataIndex == e) {count ++} })if (count > 0 ) {return '-' + params.value + '%';} else {return '+' + params.value + '%';}},},data: y2List,},{//下面的顶z: 2,type: "pictorialBar",data: yList,symbol: "diamond",symbolOffset: [0, "50%"],symbolSize: [barWidth, barWidth * 0.5],itemStyle: {normal: {color: function (params) {return colors[0];},},},},{//下面的顶z: 4,type: "pictorialBar",data: yList,symbolPosition: "end",symbol: "diamond",symbolOffset: [0, -6],symbolSize: [barWidth, barWidth * 0.5],itemStyle: {normal: {color: function (params) {let count = 0indexList.forEach( e => {if (params.dataIndex == e) {count ++} })if (count > 0 ) {return colors[2];} else {return colors[1];}},},},},{//上面的顶z: 5,type: "pictorialBar",symbolPosition: "end",data: yAndy2,symbol: "diamond",symbolOffset: [0,-6],symbolSize: [barWidth, barWidth * 0.5],itemStyle: {normal: {borderWidth: 0,color: function (params) {let count = 0indexList.forEach( e => {if (params.dataIndex == e) {count ++} })if (count > 0 ) {return colors[2];} else {return colors[1];}},},},},],dataZoom: [ //数据量大,横向排不下可开启缩放和左右滑动显示{show: true,height: 10,xAxisIndex: [0],bottom: 5,start: 0, //默认开始点end: 7, //默认结束点,即一屏显示的数据项个数handleSize: "100%",handleStyle: {color: "#d3dee5",},textStyle: {color: "#fff",},borderColor: "#90979c",},{type: "inside",show: true,height: 10,start: 1,end: 35,},],};return option;},

3、立体圆柱形

     ydChartOption(){let currData = [100,120,115,160,80] let perData = [56,80,77,70,65]let rateData = [10,5,8,12,6]let that = this;let option = {color:['#25af00'],tooltip: {trigger: 'axis',formatter: function (params) {return `<div> <div>${params[0].name}</div><div>当前:${params[0].value}</div><div>环比:${params[1].value}</div><div>涨幅:${params[2].value}%</div></div>`},},grid:{top:"30",left:'40',right:"45",bottom:"20",},xAxis: {data: ['20240901','20240902','20240903','20240904','20240905'],axisTick:{show:false,},axisLine: {lineStyle: {color: '#B7D0FF'}},axisLabel: {show: true, color:'#252525',fontSize:11,},},yAxis: [{  type:'value',axisLabel: {show: true,},axisTick:{show:false,},axisLine: {show:false},splitLine: {show: false,lineStyle: {color:'#B7D0FF',type:'dashed'},},},{  type:'value',position: 'right',axisLabel: { //y轴设置为%show: true,interval: 'auto',formatter: '{value} %',},axisTick:{show:false,},axisLine: {show:false},splitLine: {show: true,lineStyle: {color:'#B7D0FF',type:'dashed'},},},],series: [{name:'当前',data: currData,type: 'bar',barWidth:'25%',yAxisIndex: 0,smooth: true,barWidth: 16,lineStyle: {normal: {color:'#0060FF',width: 4,}},itemStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#7ab1ff' },{ offset: 1, color: '#2b70ef' }]),},},{name:'环比',data: perData,type: 'bar',barWidth:'25%',yAxisIndex: 0,smooth: true,barWidth: 16,lineStyle: {normal: {color:'rgb(0,187,84)',width: 4,}},itemStyle: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#ffba81' },{ offset: 1, color: '#fe6f04' }]),},},{name:'涨幅',data: rateData,type: 'line',yAxisIndex: 1,smooth: false,showSymbol:true,lineStyle: {normal: {color:'#25af00',width: 2,}},},//以下代码为柱状图上下的盖{//下面的底z: 3,type: "pictorialBar",data: currData,// symbol: "diamond",symbolOffset: [-10.5, 5],symbolSize: [16, 8],itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#7ab1ff' },{ offset: 1, color: '#2b70ef' }]),},},},{//上面的顶z: 4,type: "pictorialBar",symbolPosition: "end",data: currData,// symbol: "diamond",symbolOffset: [-10.5, -5],symbolSize: [16, 8],itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#7ab1ff' },{ offset: 1, color: '#2b70ef' }]),},},},{//下面的底z: 5,type: "pictorialBar",data: perData,// symbol: "diamond",symbolOffset: [10.5, 5],symbolSize: [16, 8],itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#ffba81' },{ offset: 1, color: '#fe6f04' }]),},},},{//上面的顶z: 6,type: "pictorialBar",symbolPosition: "end",data: perData,// symbol: "diamond",symbolOffset: [10.5, -5],symbolSize: [16, 8],itemStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#ffba81' },{ offset: 1, color: '#fe6f04' }]),},},},],legend: [{data:['当前','环比','涨幅'],show: true,orient: 'horizontal',right: 'left',top: 0,}]};return option;}

这篇关于在 vue2 中实现 echarts 立体方形柱状图及立体圆柱的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1139231

相关文章

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

Python位移操作和位运算的实现示例

《Python位移操作和位运算的实现示例》本文主要介绍了Python位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

利用python实现对excel文件进行加密

《利用python实现对excel文件进行加密》由于文件内容的私密性,需要对Excel文件进行加密,保护文件以免给第三方看到,本文将以Python语言为例,和大家讲讲如何对Excel文件进行加密,感兴... 目录前言方法一:使用pywin32库(仅限Windows)方法二:使用msoffcrypto-too