Echarts实现3D柱状图

2023-12-21 10:01
文章标签 实现 3d echarts 柱状图

本文主要是介绍Echarts实现3D柱状图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Echarts实现3D柱状图

    • 效果图
    • 代码

效果图

在这里插入图片描述

代码

<!--此示例下载自 https://echarts.apache.org/examples/zh/editor.html?c=bar3d-dataset&gl=1
-->
<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head><meta charset="utf-8"><title>Echarts实现3D柱状图 - qipa250</title>
</head>
<body style="height: 100%; margin: 0">
<div id="qipa250" style="height: 100%"></div><script type="text/javascript" src="https://cdn.staticfile.org/jquery/3.7.1/jquery.min.js"></script>
<!--
<script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.4.3/files/dist/echarts.min.js"></script>
-->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5.4.1/dist/echarts.min.js"></script>
<!--  www.qipa250.com 奇葩天地网--><script type="text/javascript">var chartDom = document.getElementById('qipa250');var myChart = echarts.init(chartDom);var option;const labels = ['春节', '元宵节', '端午节', '中秋节', '国庆节'];const seriesData = [{label: '春节',value: [32],},{label: '元宵节',value: [24],},{label: '端午节',value: [42],},{label: '中秋节',value: [20],},{label: '国庆节',value: [70],}]const colors = [[{offset: 0, color: 'rgba(126, 132, 191, 1)'},{offset: 1, color: 'rgba(126, 132, 191, 0.08)'},],[{offset: 0, color: 'rgba(137, 163, 164, 1)'},{offset: 1, color: 'rgba(137, 163, 164, 0.09)'},],[{offset: 0, color: 'rgba(44, 166, 166, 1)'},{offset: 1, color: 'rgba(44, 166, 166, 0.08)'},],[{offset: 0, color: 'rgba(34, 66, 186, 1)'},{offset: 1, color: 'rgba(34, 66, 186, 0.08)'},],[{offset: 0, color: 'rgba(34, 66, 186, 1)'},{offset: 1, color: 'rgba(34, 66, 186, 0.08)'},],];option = {xAxis: {axisTick: {show: false},nameTextStyle: {color: '#fff'},data: labels,},legend: {data: getlegendData(),right: '25',top: '18',icon: 'rect',itemHeight: 10,itemWidth: 10,textStyle: {color: '#000'}},yAxis: {type: 'value',axisLabel: {color: '#000'},splitLine: {show: true,lineStyle: {type: 'dashed',color: ['#ccc']}}},series: getSeriesData()};// 定义柱状图左侧图形元素const leftRect = echarts.graphic.extendShape({shape: {x: 0,y: 0,width: 19, //柱状图宽zWidth: 8, //阴影折角宽zHeight: 4 //阴影折角高},buildPath: function (ctx, shape) {const api = shape.api;const xAxisPoint = api.coord([shape.xValue, 0]);const p0 = [shape.x - shape.width / 2, shape.y - shape.zHeight];const p1 = [shape.x - shape.width / 2, shape.y - shape.zHeight];const p2 = [xAxisPoint[0] - shape.width / 2, xAxisPoint[1]];const p3 = [xAxisPoint[0] + shape.width / 2, xAxisPoint[1]];const p4 = [shape.x + shape.width / 2, shape.y];ctx.moveTo(p0[0], p0[1]);ctx.lineTo(p1[0], p1[1]);ctx.lineTo(p2[0], p2[1]);ctx.lineTo(p3[0], p3[1]);ctx.lineTo(p4[0], p4[1]);ctx.lineTo(p0[0], p0[1]);ctx.closePath();}});// 定义柱状图右侧以及顶部图形元素const rightRect = echarts.graphic.extendShape({shape: {x: 0,y: 0,width: 18,zWidth: 15,zHeight: 8},buildPath: function (ctx, shape) {const api = shape.api;const xAxisPoint = api.coord([shape.xValue, 0]);const p1 = [shape.x - shape.width / 2, shape.y - shape.zHeight / 2];const p3 = [xAxisPoint[0] + shape.width / 2, xAxisPoint[1]];const p4 = [shape.x + shape.width / 2, shape.y];const p5 = [xAxisPoint[0] + shape.width / 2 + shape.zWidth, xAxisPoint[1]];const p6 = [shape.x + shape.width / 2 + shape.zWidth,shape.y - shape.zHeight / 2];const p7 = [shape.x - shape.width / 2 + shape.zWidth,shape.y - shape.zHeight];ctx.moveTo(p4[0], p4[1]);ctx.lineTo(p3[0], p3[1]);ctx.lineTo(p5[0], p5[1]);ctx.lineTo(p6[0], p6[1]);ctx.lineTo(p4[0], p4[1]);ctx.moveTo(p4[0], p4[1]);ctx.lineTo(p6[0], p6[1]);ctx.lineTo(p7[0], p7[1]);ctx.lineTo(p1[0], p1[1]);ctx.lineTo(p4[0], p4[1]);ctx.closePath();}});// 注册图形元素echarts.graphic.registerShape('leftRect', leftRect);echarts.graphic.registerShape('rightRect', rightRect);function getlegendData() {const data = [];labels.forEach((item, index) => {data.push({name: item,itemStyle: {color: new echarts.graphic.LinearGradient(1, 0, 0, 0, colors[index]),},})})return data}function getSeriesData() {const data = [];seriesData.forEach((item, index) => {data.push({type: 'custom',name: item.label,renderItem: function (params, api) {return getRenderItem(params, api);},data: item.value,itemStyle: {color: () => {return new echarts.graphic.LinearGradient(0, 0, 0, 1, colors[index]);},},})})return data}function getRenderItem(params, api) {const index = params.seriesIndex;let location = api.coord([api.value(0) + index, api.value(1)]);var extent = api.size([0, api.value(1)]);return {type: 'group',children: [{type: 'leftRect',shape: {api,xValue: api.value(0) + index,yValue: api.value(1),x: location[0],y: location[1]},style: api.style()},{type: 'rightRect',shape: {api,xValue: api.value(0) + index,yValue: api.value(1),x: location[0],y: location[1]},style: api.style()}]};}option && myChart.setOption(option);window.addEventListener('resize', myChart.resize);</script>
</body>
</html>

这篇关于Echarts实现3D柱状图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Nginx更新SSL证书的实现步骤

《Nginx更新SSL证书的实现步骤》本文主要介绍了Nginx更新SSL证书的实现步骤,包括下载新证书、备份旧证书、配置新证书、验证配置及遇到问题时的解决方法,感兴趣的了解一下... 目录1 下载最新的SSL证书文件2 备份旧的SSL证书文件3 配置新证书4 验证配置5 遇到的http://www.cppc

Nginx之https证书配置实现

《Nginx之https证书配置实现》本文主要介绍了Nginx之https证书配置的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起... 目录背景介绍为什么不能部署在 IIS 或 NAT 设备上?具体实现证书获取nginx配置扩展结果验证

SpringBoot整合 Quartz实现定时推送实战指南

《SpringBoot整合Quartz实现定时推送实战指南》文章介绍了SpringBoot中使用Quartz动态定时任务和任务持久化实现多条不确定结束时间并提前N分钟推送的方案,本文结合实例代码给大... 目录前言一、Quartz 是什么?1、核心定位:解决什么问题?2、Quartz 核心组件二、使用步骤1

使用Redis实现会话管理的示例代码

《使用Redis实现会话管理的示例代码》文章介绍了如何使用Redis实现会话管理,包括会话的创建、读取、更新和删除操作,通过设置会话超时时间并重置,可以确保会话在用户持续活动期间不会过期,此外,展示了... 目录1. 会话管理的基本概念2. 使用Redis实现会话管理2.1 引入依赖2.2 会话管理基本操作

mybatis-plus分表实现案例(附示例代码)

《mybatis-plus分表实现案例(附示例代码)》MyBatis-Plus是一个MyBatis的增强工具,在MyBatis的基础上只做增强不做改变,为简化开发、提高效率而生,:本文主要介绍my... 目录文档说明数据库水平分表思路1. 为什么要水平分表2. 核心设计要点3.基于数据库水平分表注意事项示例

C#高效实现在Word文档中自动化创建图表的可视化方案

《C#高效实现在Word文档中自动化创建图表的可视化方案》本文将深入探讨如何利用C#,结合一款功能强大的第三方库,实现在Word文档中自动化创建图表,为你的数据呈现和报告生成提供一套实用且高效的解决方... 目录Word文档图表自动化:为什么选择C#?从零开始:C#实现Word文档图表的基本步骤深度优化:C

nginx跨域访问配置的几种方法实现

《nginx跨域访问配置的几种方法实现》本文详细介绍了Nginx跨域配置方法,包括基本配置、只允许指定域名、携带Cookie的跨域、动态设置允许的Origin、支持不同路径的跨域控制、静态资源跨域以及... 目录一、基本跨域配置二、只允许指定域名跨域三、完整示例四、配置后重载 nginx五、注意事项六、支持

Qt实现对Word网页的读取功能

《Qt实现对Word网页的读取功能》文章介绍了几种在Qt中实现Word文档(.docx/.doc)读写功能的方法,包括基于QAxObject的COM接口调用、DOCX模板替换及跨平台解决方案,重点讨论... 目录1. 核心实现方式2. 基于QAxObject的COM接口调用(Windows专用)2.1 环境

MySQL查看表的历史SQL的几种实现方法

《MySQL查看表的历史SQL的几种实现方法》:本文主要介绍多种查看MySQL表历史SQL的方法,包括通用查询日志、慢查询日志、performance_schema、binlog、第三方工具等,并... 目录mysql 查看某张表的历史SQL1.查看MySQL通用查询日志(需提前开启)2.查看慢查询日志3.

Java实现字符串大小写转换的常用方法

《Java实现字符串大小写转换的常用方法》在Java中,字符串大小写转换是文本处理的核心操作之一,Java提供了多种灵活的方式来实现大小写转换,适用于不同场景和需求,本文将全面解析大小写转换的各种方法... 目录前言核心转换方法1.String类的基础方法2. 考虑区域设置的转换3. 字符级别的转换高级转换