当前位置: 首页 > news >正文

Echarts-3D柱状图

通过Echarts的echarts.graphic.extendShape实现真正的3D柱状图
思路就是通过调整顶部面(CubeTop)、左侧面(CubeLeft)、右侧面(CubeRight)来决定柱状图的宽窄
建议优先调整顶部面,一般c1不需要动

// echarts-3D-bar-config.js
import Vue from "vue";const echarts = Vue.prototype.echarts;const CubeLeft = echarts.graphic.extendShape({shape: {x: 0,y: 0},buildPath: function (ctx, shape) {const xAxisPoint = shape.xAxisPoint;// 顶部右侧顶点const c1 = [shape.x, shape.y];// 顶部左侧顶点const c2 = [shape.x - 15, shape.y - 8];// 底部左侧const c3 = [xAxisPoint[0] - 15, xAxisPoint[1] - 8];// 底部右侧const c4 = [xAxisPoint[0], 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 CubeRight = echarts.graphic.extendShape({shape: {x: 0,y: 0},buildPath: function (ctx, shape) {const xAxisPoint = shape.xAxisPoint;// 顶部左侧顶点const c1 = [shape.x, shape.y];// 底部左侧顶点const c2 = [xAxisPoint[0], xAxisPoint[1]];// 底部右侧顶点const c3 = [xAxisPoint[0] + 15, xAxisPoint[1] - 8];// 顶部右侧顶点const c4 = [shape.x + 15, shape.y - 8];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, shape.y];// 右侧顶点const c2 = [shape.x + 15, shape.y - 8];// 顶部顶点const c3 = [shape.x, shape.y - 15];// 右侧顶点const c4 = [shape.x - 15, shape.y - 8];ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();}
});
echarts.graphic.registerShape("CubeLeft", CubeLeft);
echarts.graphic.registerShape("CubeRight", CubeRight);
echarts.graphic.registerShape("CubeTop", CubeTop);

然后在build-bar-option中引用即可
这里主要就是把series中的内容复制过来直接用就行了


import Vue from "vue";
import "./echarts-3D-Bar-config"const echarts = Vue.prototype.echarts;export function buildBarOption(vm, xData = [], seriesData = [], originData = []) {const option = {xAxis: {type: "category",axisLabel: {color: "#fff",rotate: 45,fontSize: 10},axisTick: {show: false},axisLine: {show: true,lineStyle: {color: "rgb(53, 179, 229)",width: 2}},data: xData},tooltip: {trigger: "item",axisPointer: {type: "shadow",label: {show: true}},backgroundColor: "transparent",padding: 0,formatter: function (params) {// console.log(params)return `<div style="padding: 15px; background: linear-gradient(180.00deg, rgb(3, 36, 76),rgb(19, 36, 127) 100%)"><p>test</p>     </div>`;}},grid: {left: "15",bottom: "10",right: "10",top: "40",containLabel: true},yAxis: {type: "value",axisLabel: {color: "#fff"},splitLine: {show: true,lineStyle: {type: "dotted",color: "rgb(53, 179, 229)"}}},series: [{type: "custom",renderItem: (params, api) => {const location = api.coord([api.value(0), api.value(1)]);return {type: "group",children: [{type: "CubeLeft",shape: {api,xValue: api.value(0),yValue: api.value(1),x: location[0],y: location[1],xAxisPoint: api.coord([api.value(0), 0])},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: "#3B80E2"},{offset: 1,color: "#49BEE5"}])}},{type: "CubeRight",shape: {api,xValue: api.value(0),yValue: api.value(1),x: location[0],y: location[1],xAxisPoint: api.coord([api.value(0), 0])},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: "#3B80E2"},{offset: 1,color: "#49BEE5"}])}},{type: "CubeTop",shape: {api,xValue: api.value(0),yValue: api.value(1),x: location[0],y: location[1],xAxisPoint: api.coord([api.value(0), 0])},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: "#3B80E2"},{offset: 1,color: "#49BEE5"}])}}]};},data: seriesData},{data: seriesData,type: "bar",barWidth: 13,itemStyle: {color: "transparent"}}]};return option;
}
http://www.lryc.cn/news/208122.html

相关文章:

  • vue中组件传值 引用页面与组件页面绑定参数 vue省市地区街道级联选择组件
  • componentDidMount只执行一次的解决方法
  • React之diff原理
  • ElasticSearch中关于Nasted嵌套查询的介绍:生动案例,通俗易懂,彻底吸收
  • 系列二、Spring的优缺点是什么
  • ESP32网络开发实例-HTTP-GET请求
  • PHP:json_encode和json_decode用法
  • Kafka-Java二:Spring配置kafka消息发送端的缓冲区
  • 【ArcGIS模型构建器】05:批量为多个矢量数据添加相同的字段
  • 坤坤的悲伤生活
  • 职业技术认证:《研发效能(DevOps)工程师》——开启职业发展新篇章
  • gin 框架出现runtime error: index out of range [0] with length 0
  • 【高阶数据结构】B树
  • Android-Framework 应用间跳转时,提供 Android Broadcast 通知
  • 【Javascript】函数返回值的作用
  • 蓝桥杯 Java k倍区间
  • 万宾科技亮相2023中国传感器与应用技术大会,创始人CEO发表演讲
  • #力扣:LCP 06. 拿硬币@FDDL
  • 【Node.js】暴露自定义响应头和预检请求的时机
  • 包管理工具与配置文件package.json
  • uni-app:解决异步请求返回值问题
  • <多线程章节七>wait() 和 notify()
  • 竹云产品入选《2023年度上海市网络安全产业创新攻关成果目录》
  • 客户端负载均衡策略:loadBalancer,ribbon
  • canvas基础3 -- 交互
  • Flutter——最详细(Scaffold)使用教程
  • C语言编写图形化界面-创建按钮-为其指定样式
  • C++并发与多线程(7) | 创建多个线程时数据共享的问题
  • 进程间通信(匿名管道、命名管道、消息队列、共享内存、信号量、信号、Socket)
  • 浅谈中国汽车充电桩行业市场状况及充电桩选型的介绍