echarts bar3D画出圆角立方体模拟建筑

结果展示

在这里插入图片描述

重点

 bar3D中圆角属性:
 		roundCap: true  //开启圆角(echarts官方文档中没有)
        bevelSize: .6   //圆角程度
        barSize: 12.5   //立方体大小

半球形使用 surface 类型,曲线方程如下

			parametricEquation: {
                  u: {
                      min: 0,
                      max: Math.PI,
                      step: Math.PI / 20
                  },
                  v: {
                      min: 0,
                      max: Math.PI,
                      step: Math.PI / 20
                  },
                  x: function (u, v) {
                      return that.locaX/2 * Math.sin(v) * Math.cos(u) + that.locaX/2;
                  },
                  y: function (u, v) {
                      return that.locaY/2 * Math.cos(v) + that.locaY/2;
                  },
                  z: function (u, v) {
                      return that.locaZ * Math.sin(v) * Math.sin(u);
                  }
              }

完整代码

body

<div id="chartDom"></div>

script

initChart() {
      const that = this
      var chartDom = document.getElementById("chartDom");
      this.chart = echarts.init(chartDom, "dark");

      let option = {
        xAxis3D: {
          name: "x", //x轴显示为x
          type: "value",
          min: 0,
          max: this.locaX,
          axisTick: {
            show: true, //显示每个值对应的刻度
          },
          axisLabel: {
            show: true, // 是否显示刻度(刻度上的数字,或者类目), false为隐藏,true为显示
            distance: 0
          },
          itemStyle: {
            borderColor: "#e7e7e7",
            backgroundColor: "#e7e7e7",
          },
        },
        yAxis3D: {
          name: "y", //y轴显示为y
          type: "value",
          splitNumber: 5,
          axisTick: {
            show: true, //显示每个值对应的刻度
          },
          min: 0,
          max: this.locaY,
          axisLabel:{
            show: true, // 是否显示刻度(刻度上的数字,或者类目), false为隐藏,true为显示
            distance: 0
          },
        },
        zAxis3D: {
          name: "z", //z轴显示为z
          type: "value",
          min: -12.5/50*this.locaZ,
          // min: 0,
          max: this.locaZ,
          axisTick: {
            show: false, //显示每个值对应的刻度
          },
        },
        grid3D: {
          axisLine: {
            lineStyle: {
              //坐标轴样式
              color: "#070707", //轴线颜色
              opacity: 0.8, //(单个刻度不会受影响)
              width: 1, //线条宽度
            }
          },
          axisPointer: {
            lineStyle: {
              color: "#f56c6c", //坐标轴指示线
              width: 2,
            },
            show: true, //展示坐标轴指示线
          },
          viewControl: {
            // autoRotate: true,//旋转展示
            projection: "perspective",
            // beta:0,
            distance: 200, //与视角的距离,值越大,图离视角越远,图越小
            alpha: 15, //绕x轴旋转的角度(上下旋转),增大,视角顺时针增大(向上)
            beta: 120, //绕y轴旋转的角度(左右旋转),增大,视角逆时针增大(向右)
            center: [-15, -5, -10], //第一个参数:增大,视角沿x轴正方向水平右移动(图向左);第二个参数:增大,视角沿y轴正方向垂直向上移动(图向下);第三个参数:增大,视角向z轴正方向移动(图变小)
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#8f8f8f",
            },
          },
          boxWidth: 120,
          boxHeight: 70,
          boxDepth: -120,
          top: -100,
        },
        series: [
          {
            // 外壳
              type: 'surface',
              parametric: true,
              shading: 'lambert',
              silent: true,
              wireframe: {
                  show: false
              },
              itemStyle: {
                  color: '#fff',
                  opacity: 0.3
              },
              parametricEquation: {
                  u: {
                      min: 0,
                      max: Math.PI,
                      step: Math.PI / 20
                  },
                  v: {
                      min: 0,
                      max: Math.PI,
                      step: Math.PI / 20
                  },
                  x: function (u, v) {
                      return 10/2 * Math.sin(v) * Math.cos(u) + 10/2;
                  },
                  y: function (u, v) {
                      return 10/2 * Math.cos(v) + 10/2;
                  },
                  z: function (u, v) {
                      return 50 * Math.sin(v) * Math.sin(u);
                  }
              }
          },
          {
            // 1
            type: 'bar3D',
            data: [[ 15700 / 55400 * 10, 36200 / 55400 * 10, 16.5 / 50 * 10]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 10,
            depth: 1,
            barGap: '-100%',
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '1';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 2
            type: 'bar3D',
            data: [[ 14700 / 55400 * 10, 30000 / 55400 * 10, 22.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 10,
            depth: 1,
            barGap: '-100%',
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '2';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          
          {
            // 3
            type: 'bar3D',
            data: [[ 15700 / 55400 * 10, 20700 / 55400 * 10, 22.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 19,
            depth: 1,
            barGap: '-100%',
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '3';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 4
            type: 'bar3D',
            data: [[5, 5, -8.8],[5, 5, 4.8]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: 0.2,
            barSize: 25,
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '4';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#c9c9c9',
              opacity: 0.9
            }
          },
          {
            // 5
            type: 'bar3D',
            data: [[ 26700 / 55400 * 10, 14700 / 55400 * 10, 16.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 12.5,
            depth: 1,
            barGap: '-100%',
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '5';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 6
            type: 'bar3D',
            data: [[ 33700 / 55400 * 10, 15700 / 55400 * 10, 22.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 12.5,
            depth: 1,
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '6';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 7
            type: 'bar3D',
            data: [[ 35700 / 55400 * 10, 42700 / 55400 * 10, 22.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 12.5,
            depth: 1,
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '7';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 8
            type: 'bar3D',
            data: [[ 39700 / 55400 * 10, 33700 / 55400 * 10, 16.5]],
            shape: 'cube',
            // 圆角
            roundCap: true,
            bevelSize: .6,
            barSize: 12.5,
            depth: 1,
            shading: 'lambert',
            silent: true,
            label: {
                show: true,
                formatter: function (param) {
                    return '8';
                },
                position: 'insideTop',
                textStyle:{
                  color: '#000',
                  fontSize: 13
                }
            },
            itemStyle: {
              color: '#8c92b9',
              opacity: 0.9
            }
          },
          {
            // 平面
              type: 'surface',
              parametric: false,
              silent: true,
              wireframe: {
                  show: false
              },
              itemStyle: {
                  color: '#fff',
                  opacity: .3
              },
              data: [
                [0,0,0],[10,0,0],[0,10,0],[10,10,0]
              ]
          },
        ],
        backgroundColor: "#235d7e",
      };
      option && this.chart.setOption(option);
      window.addEventListener("resize", () => {
        this.chart.resize();
      });
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

格格不入ち

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值