echarts 3D立体圆柱堆叠柱状图

3D立体圆柱堆叠柱状图

import * as echarts from 'echarts';

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

let barData1 = [10, 15, 8, 18, 9, 12, 14];
let barData2 = [8, 6, 5, 8, 4, 6, 4];
let barData3 = [8, 5, 12, 8, 20, 14, 17];
let dateX = [`周一`, '周二', '周三', '周四', '周五', '周六', '周日'];
let pictorialBar = [];
// let pictorialBar2 = [];
// let pictorialBar2 = [];
// let pictorialBar3 = [];
for (let i = 0; i < barData1.length; i++) {
  // pictorialBar.push(barData1[i] + barData2[i])
  // pictorialBar2.push(barData1[i] + barData2[i] + barData3[i])
  if (barData2[i] > 0) {
    pictorialBar.push(Number(barData1[i]) + Number(barData2[i]));
  } else {
    pictorialBar.push('');
  }
  // if (barData3[i] > 0) {
  //   pictorialBar2.push(Number(barData3[i]));
  // } else {
  //   pictorialBar2.push('');
  // }
}

option = {
  title: {
    text: '完成情况',
    x: 'center',
    textStyle: {
      //文字颜色
      color: '#000',
      //字体风格,'normal','italic','oblique'
      // fontStyle: 'normal',
      //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
      fontWeight: '400',
      //字体系列
      // fontFamily: 'sans-serif',
      //字体大小
      fontSize: 16
    }
  },
  legend: {
    orient: 'horizontal',
    x: 'center',
    y: 'bottom',
    // padding: this.isDeptBedUsed == '1' ? [0, 0, 20, 0] : [0, 0, 0, 0],
    itemWidth: 12,
    itemHeight: 12,
    data: ['未完成', '申报数量', '实际完成量'],
    icon: 'rect'
  },
  dataZoom: this.dataZoom,
  backgroundColor: '#fff',
  tooltip: {
    trigger: 'axis',
    show: true,
    formatter: function (value) {
      // console.log(value);
      return `<span>${value[1].axisValueLabel}</span></br>
                            <div style="display: inline-block;
                               width:  10px;
                               height: 20px;
                               color:${value[1].color.colorStops[0].color};!important
                               ">●</div>&nbsp;<span>${value[1].seriesName}
                               </span>&nbsp;&nbsp;&nbsp;&nbsp;<span><strong>${value[1].data}</strong></span></br>

                               <div style="display: inline-block;
                               width:  10px;
                               height: 20px;
                               color:${value[3].color};!important
                               ">●</div>&nbsp;<span>${value[3].seriesName}
                               </span>&nbsp;&nbsp;&nbsp;&nbsp;<span><strong>${value[3].data}</strong></span></br>

                              <div style="display: inline-block;
                               width:  10px;
                               height: 20px;
                               color:${value[6].color.colorStops[0].color};!important
                               ">●</div>&nbsp;<span>${value[6].seriesName}
                               </span>&nbsp;&nbsp;&nbsp;&nbsp;<span><strong>${value[6].data}</strong></span></br>
                

                              `;
    }
  },
  grid: {
    left: '2%',
    right: '2%',
    bottom: '14%',
    top: '15%',
    containLabel: true
  },
  xAxis: {
    data: dateX,
    axisLabel: {
      margin: 20,
      // show: true,
      // interval: 0,
      textStyle: {
        color: '#888',
        fontSize: 14
      }
    }
  },
  yAxis: {
    axisLabel: {
      margin: 20,
      textStyle: {
        color: '#888',
        fontSize: 14
      }
    }
  },
  series: [
    // 底
    {
      name: '申报数量',
      type: 'pictorialBar',
      //圆片大小
      symbolSize: [16, 6],
      //圆片位置
      symbolOffset: [-8, 3],
      //显示层级
      z: 12,
      itemStyle: {
        //lenged文本
        color: '#a5cc0c'
      },

      data: barData1
    },

    //柱状图
    {
      name: '申报数量',
      type: 'bar',
      barWidth: 16,
      // barCategoryGap: '10%',
      barGap: '2%',
      barCategoryGap: '-4%',
      stack: 'group1',
      // barGap: '10%',
      itemStyle: {
        //lenged文本
        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
          {
            offset: 0,
            color: '#dff77e'
          },
          {
            offset: 1,
            color: '#dff77e'
          }
        ])
      },

      data: barData1
    },
    {
      name: '',
      type: 'pictorialBar',
      symbolSize: [16, 6],
      symbolOffset: [-8, -3],
      symbolPosition: 'end',
      z: 12,
      itemStyle: {
        //lenged文本
        color: '#27b9d6'
      },
      data: barData1
    },

    {
      name: '未完成',
      type: 'bar',
      barWidth: 30,
      barGap: '2%',
      barCategoryGap: '-4%',
      stack: 'group1',
      itemStyle: {
        // barBorderRadius: 20,
        color: '#8fe6f7'
      },
      data: barData2
    },
    {
      name: '', //头部
      type: 'pictorialBar',
      symbolSize: [16, 6],
      symbolOffset: [-8, -2],
      symbolPosition: 'end',

      z: 12,
      itemStyle: {
        //lenged文本
        color: '#27b9d6'
      },
      data: pictorialBar
    },

    // 底
    {
      name: '',
      type: 'pictorialBar',
      symbolSize: [16, 6],
      symbolOffset: [8, 3],
      z: 12,
      itemStyle: {
        //lenged文本
        color: '#eb47b7'
      },

      data: barData3
    },

    //柱状图
    {
      name: '实际完成量',
      type: 'bar',
      barWidth: 16,
      barGap: '2%',
      barCategoryGap: '-4%',
      stack: 'group2',
      itemStyle: {
        //lenged文本
        color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
          {
            offset: 0,
            color: '#f09cd6'
          },
          {
            offset: 1,
            color: '#f09cd6'
          }
        ])
      },

      data: barData3
    },
    // 顶
    {
      name: '',
      type: 'pictorialBar',
      symbolSize: [16, 6],
      symbolOffset: [8, -3],
      symbolPosition: 'end',
      z: 12,
      itemStyle: {
        //lenged文本
        color: '#eb47b7'
      },
      data: barData3
    }
  ]
};

option && myChart.setOption(option);

在这里插入图片描述

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Echarts 是一个非常流行的数据可视化库,支持多种图表类型。在 Echarts 中,3D 圆柱柱状图可以使用柱状图(bar)系列,同时设置 3D 属性即可实现。 以下是一个简单的示例代码: ```javascript // 初始化echarts实例 var myChart = echarts.init(document.getElementById('myChart')); // 指定图表的配置项和数据 var option = { tooltip: {}, visualMap: { show: false, dimension: 2, min: 0, max: 100, inRange: { color: ['#d94e5d','#eac736','#50a3ba'].reverse() } }, xAxis3D: { type: 'category', data: ['Apple', 'Samsung', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo'] }, yAxis3D: { type: 'value' }, zAxis3D: { type: 'category', data: ['Q1', 'Q2', 'Q3', 'Q4'] }, grid3D: { boxWidth: 200, boxDepth: 80, light: { main: { intensity: 1.2 }, ambient: { intensity: 0.3 } } }, series: [{ type: 'bar3D', data: [ [0, 0, 78], [1, 0, 60], [2, 0, 85], [3, 0, 93], [4, 0, 82], [5, 0, 86], [0, 1, 58], [1, 1, 75], [2, 1, 86], [3, 1, 69], [4, 1, 91], [5, 1, 92], [0, 2, 88], [1, 2, 76], [2, 2, 67], [3, 2, 78], [4, 2, 93], [5, 2, 92], [0, 3, 92], [1, 3, 79], [2, 3, 88], [3, 3, 93], [4, 3, 81], [5, 3, 76] ], shading: 'lambert', label: { show: true, textStyle: { fontSize: 16, borderWidth: 1 } }, itemStyle: { opacity: 0.8 } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); ``` 在这段代码中,我们使用了 Echarts 的 bar3D 系列,通过设置 x、y、z 轴数据来创建 3D 圆柱柱状图。同时,我们还设置了 grid3D 属性,来控制图表的 3D 效果。 以上是一个简单的实现,你可以根据自己的需求来设置不同的参数和属性,来达到更好的可视化效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值