效果如下:

<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title>模拟3D柱状图+渐变色柱子</title><scripttype="text/javascript"src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script><script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script></head><body><div id="bar" style="width: 1000px; height: 500px"></div><script type="text/javascript">let myBarChart = echarts.init(document.getElementById('bar'))// 得到的数据let seriesData1 = [{name: '国君',value: 20,},{name: '中信',value: 100,},{name: '中金',value: 50,},{name: '华泰',value: 44,},{name: '海通',value: 12,},]// 柱子降序排列seriesData1.sort((a, b) => b.value - a.value)console.log(seriesData1)// x轴证券公司名称let xData = []seriesData1.forEach((item) => {xData.push(item.name)})// 数据let seriesData = []seriesData1.forEach((item) => {seriesData.push(item.value)})// 颜色组let linearArr = ['#4D89FF','#84BEFF','#3C6CCC','#FFA95D','#FF7F0E','#CC650B','#E46F07',]// 绘制左侧面const offsetX = 10,sliderWidth = 7,offsetTick = 10const CubeLeft = echarts.graphic.extendShape({shape: {x: 0,y: 0,},buildPath: function (ctx, shape) {// shape是从custom传入的const api = shape.apiconst xAxisPoint = api.coord([shape.xValue, 0])const c0 = [shape.x - offsetTick, shape.y]const c1 = [shape.x - offsetTick + offsetX, shape.y]const c2 = [xAxisPoint[0] - offsetTick + offsetX, xAxisPoint[1]]const c3 = [xAxisPoint[0] - offsetTick, xAxisPoint[1]]ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath()},})// 绘制右侧面const CubeRight = echarts.graphic.extendShape({shape: {x: 0,y: 0,},buildPath: function (ctx, shape) {const api = shape.apiconst xAxisPoint = api.coord([shape.xValue, 0])const c1 = [shape.x - offsetTick + offsetX, shape.y]const c2 = [shape.x - offsetTick + offsetX + sliderWidth,shape.y - sliderWidth,]const c3 = [xAxisPoint[0] - offsetTick + offsetX + sliderWidth,xAxisPoint[1] - sliderWidth + 4,]const c4 = [shape.x - offsetTick + offsetX, xAxisPoint[1]]ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath()},})// 绘制顶面const CubeTop = echarts.graphic.extendShape({shape: {x: 0,y: 0,},buildPath: function (ctx, shape) {const c1 = [shape.x - offsetTick, shape.y]const c2 = [shape.x - offsetTick + offsetX, shape.y] // 右点const c3 = [shape.x - offsetTick + offsetX + sliderWidth,shape.y - sliderWidth,]const c4 = [shape.x - offsetTick + sliderWidth, shape.y - sliderWidth]ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).lineTo(c1[0], c1[1]).closePath()},})// 注册三个面图形echarts.graphic.registerShape('CubeLeft', CubeLeft)echarts.graphic.registerShape('CubeRight', CubeRight)echarts.graphic.registerShape('CubeTop', CubeTop)option = {xAxis: {axisTick: {// 不显示坐标刻度show: false,},axisLine: {show: false, // 不显示坐标轴线},data: xData,},yAxis: {type: 'value',// 不显示网格splitLine: {show: false,},},series: [{type: 'custom',data: seriesData,itemStyle: {shadowColor: '#000',shadowBlur: 100,},renderItem: function (params, api) {let location = api.coord([api.value(0), api.value(1)])console.log(seriesData[params.dataIndex])return {type: 'group',children: [// 柱子前面{type: 'CubeLeft',// shape 属性描述了这个矩形的像素位置和大小shape: {api,xValue: api.value(0), //表示取出当前 dataItem 中第一个维度的数值yValue: api.value(0),x: location[0],y: location[1],},style: {//柱子阴影shadowColor:xData[params.dataIndex] === '海通'? '#FF7F0E': '#8DD0FA',shadowOffsetX: 0,shadowOffsetY: 0,shadowBlur: 7,// 颜色fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color:xData[params.dataIndex] === '海通'? linearArr[4]: linearArr[0],},{offset: 1,color:xData[params.dataIndex] === '海通'? linearArr[3]: linearArr[1],},]),},},// 柱子侧面{type: 'CubeRight',shape: {api,xValue: api.value(0),yValue: api.value(1),x: location[0],y: location[1],},style: {//柱子阴影shadowColor:xData[params.dataIndex] === '海通'? '#FF7F0E': '#8DD0FA',shadowOffsetX: 0,shadowOffsetY: 0,shadowBlur: 7,//颜色fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color:xData[params.dataIndex] === '海通'? linearArr[6]: linearArr[2],},{offset: 1,color:xData[params.dataIndex] === '海通'? linearArr[5]: linearArr[2],},]), //平面颜色},},// 柱子顶部{type: 'CubeTop',shape: {api,xValue: api.value(0),yValue: api.value(1),x: location[0],y: location[1],},style: {//柱子阴影shadowColor:xData[params.dataIndex] === '海通'? '#FF7F0E': '#8DD0FA',shadowOffsetX: 0,shadowOffsetY: 0,shadowBlur: 7,fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color:xData[params.dataIndex] === '海通'? linearArr[4]: linearArr[0],},{offset: 1,color:xData[params.dataIndex] === '海通'? linearArr[3]: linearArr[1],},]), //平面颜色},},],}},},],}myBarChart.setOption(option)</script></body>
</html>

Echarts-实现3D柱状图显示,并单个柱子变色相关推荐

  1. echarts怎么实现立体柱状图_在vue项目中使用echarts制作3d柱状图

    在上一篇文章我们讲到构建项目,这篇文章,我们就来讲解一下,在vue项目中使用echarts制作3d柱状图. 还请看我娓娓写来. 1.第一步当然还是进入你所在项目的文件夹. 2.第二步使用npm安装你所 ...

  2. echarts自定义renderItem柱状图,每个系列柱子数不一样

    话不多说,先上图 业务需求是,在[前期库存中],显示四年的数量:后面的1-12月每个系列中最多显示两个柱子. 在echarts官方实例中,系列的数量是由 series 数组中的数量决定的,也就是说该数 ...

  3. 在vue中使用Echarts的3D柱状图

    该文章为记录,避免再次踩坑 安装所需依赖版本: "echarts": "^4.9.0", "echarts-gl": "^1.1. ...

  4. echarts动态渲染柱状图背景颜色以及顶部数值

    第一种 单个柱子变色 众所周知 柱状图的背景色在series下的 itemStyle 的color下修改  不同数据让每个柱状图背景颜色不同  这个时候就需要自定义  所以我在color后跟了一个箭头 ...

  5. echarts 3d柱状图

    3d柱状图主要是创建左右两个面,也就是两个柱子,左右两个面颜色稍微要有点不一样,形成一点点对比就行,然后上下用 type: "pictorialBar" 象形柱图来实现底部和顶部的 ...

  6. echarts——实现3D地图+3D柱状图 效果——粗糙代码记录——技能提升

    最近看到同事在弄下面的这个图,这个图是从网上看到的,是某个网站的收费项目: 收费模板:¥29.9元购买,且必须是高级版+尊享版才能够购买这个... 死贵!!! 所以,最后的决定是通过echarts中的 ...

  7. 《前端》echarts排行榜,类目名字在柱子上方全部显示,前三名序号使用自定义图片背景--什么鬼待处理

    echarts排行榜,类目名字在柱子上方全部显示,前三名序号使用自定义图片背景https://blog.csdn.net/orangeverity/article/details/107160849 ...

  8. c++ 显示三维散点图_【无机纳米材料科研制图——OriginLab 0210】Origin多组柱状图3D柱状图及3D散点图...

    此篇,我们来分享Origin绘制多组柱状图.立体柱状图和三维散点图. 一.多组柱状图 1)准备数据. 准备数据,并点击Plot-->Column/Bar/Pie-->Column进行绘制. ...

  9. echarts制作图表同时有3d柱状图与折线图

    echarts制作图表同时有3d柱状图与折线图 工作遇到,小可爱们可直接抄作业,使用的pictorialBar 工作遇到,小可爱们可直接抄作业,使用的pictorialBar echarts封装,使用 ...

最新文章

  1. WPF 支持分组互斥的 RadioButton 式单选菜单
  2. go defer 语句会延迟函数的执行直到上层函数返回。
  3. python expect模块_PYTHON基础语法全面总结
  4. boost------signals2的使用1(Boost程序库完全开发指南)读书笔记
  5. Usermod 命令详解
  6. js代码自动排版_接口测试平台代码实现9:菜单常显
  7. 微型计算机开机密码丢失,校诡实录微机教室攻略 电脑密码是多少[多图]
  8. plex 乱码_Plex Media Center现在支持播客
  9. C++类与对象(05)
  10. DELETE_FAILED_INTERNAL_ERROR Error while Installing APK
  11. .xyz域名注册总量TOP10:阿里云挤进十强 位居榜尾
  12. 【python基础语法】python实现交换操作a,b = b,a的原理
  13. R语言作图之ggplot2初识(1)
  14. python打开autocad软件_利用Python自动化操作AutoCAD的实现
  15. 三菱无机房电梯故障代码查询_三菱无机房电梯的故障代码
  16. C++17 结构化绑定
  17. 暗影精灵三 英伟达显卡 Ubuntu16.04 安装网卡驱动连接wifi
  18. Java最新面试题100道,包含答案示例(1-10题)
  19. mongodb系列02-------深入理解索引原理
  20. Starling 改变Juggler播放速度

热门文章

  1. ro模式数据库mysql_ro数据库-和ro数据库相关的内容-阿里云开发者社区
  2. Kafka的安装与配置
  3. 华为AC外置Portal认证方案配置步骤指南
  4. 计算机组成原理 启航教育,2021计算机考研:计算机组成原理知识点CPU的功能和基本结构...
  5. 【Android SDM660源码分析】- 01 - 如何创建 UEFI XBL Protocol DXE_DRIVER 驱动及UEFI_APPLICATION 应用程序
  6. 5G需要什么APP小程序?哪里有免费制作5G小程序APP和网站
  7. 微信麻将连接服务器失败,微乐麻将授权失败是怎么回事?微乐麻将怎么用微信登录?...
  8. python文件操作和绘制曲线
  9. 【微信小程序-初级实战】商品/表单编辑
  10. 使用Xamarin开发(一)安装配置