ECharts 3D柱状图

在这里插入图片描述

是一个视觉的实现方式,用到的柱状图bar和象形柱图pictorialBar

const data = [
  { name: '1班', num: 35, full: 40 },
  { name: '2班', num: 32, full: 42 },
  { name: '3班', num: 38, full: 45 },
  { name: '4班', num: 40, full: 50 },
  { name: '5班', num: 28, full: 41 },
  { name: '6班', num: 31, full: 43 }
]
let xData = []
let nData = []
let fData = []
let tData = []
data.forEach(item => {
  xData.push(item.name)
  nData.push({
    value: item.num,
    full: item.full
  })
  fData.push({
    value: item.full,
    num: item.num
  })
  tData.push(1)
})
function colorBg(index, light) {
  let colors = ['#c13f32', '#f39c28', '#eb6720', '#2aac63', '#2d7bd5']
  // 稍亮的颜色
  if (light) {
    colors = ['#e75042', '#f3c52c', '#f58447', '#2cc06f', '#3496d8']
  }
  let num = index
  if (index > (colors.length - 1)) {
    num = index % colors.length
  }
  return colors[num]
}
var chart = echarts.init(document.getElementById('chart'))
chart.setOption({
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'none'
    },
    formatter: function (data) {
      var t = data[3]
      return t.axisValue + '<br/>' + '总人数:\xa0' + t.data.full + '<br/>签到数:\xa0' + t.value
    }
  },
  grid: {
    left: 100,
    bottom: 100
  },
  xAxis: {
    data: xData,
    axisTick: {
      show: false
    },
    axisLine: {
      show: false
    },
    axisLabel: {
      interval: 0,
      textStyle: {
        color: '#000'
      },
      margin: 20, //刻度标签与轴线之间的距离。
    },

  },
  yAxis: {
    splitLine: {
      show: false
    },
    axisTick: {
      show: false
    },
    axisLine: {
      show: false
    },
    axisLabel: {
      textStyle: {
        color: '#000'
      },
    }
  },
  series: [
    // 顶部圆片
    {
      type: 'pictorialBar',
      symbolSize: [45, 8],
      symbolOffset: [0, -4],
      z: 2,
      symbolPosition: 'end',
      itemStyle: {
        color: '#c3d0e3',
        opacity: 1,
      },
      label: {
        show: true,
        color: '#000',
        position: 'top',
        formatter: function (data) {
          return data.data.num
        }
      },
      emphasis: {
        label: {
          fontWeight: 'bold'
        }
      },
      data: fData
    },
    // 未绑定区域
    {
      name: '',
      type: 'bar',
      barWidth: 45,
      barGap: '-100%',
      z: 0,
      itemStyle: {
        color: '#c3d0e3',
        opacity: .7,
      },
      data: fData
    },
    // 绑定区域圆片
    {
      type: 'pictorialBar',
      symbolSize: [45, 8],
      symbolOffset: [0, -4],
      z: 3,
      itemStyle: {
        opacity: 1,
        color: function (params) {
          return colorBg(params.dataIndex, 'light')
        }
      },
      symbolPosition: 'end',
      data: nData
    },
    // 绑定区域
    {
      name: '已绑定',
      type: 'bar',
      barWidth: 45,
      z: 2,
      barGap: '-100%',
      itemStyle: {
        color: function (params) {
          return colorBg(params.dataIndex)
        }
      },
      data: nData
    },
    // 底部圆片
    {
      type: 'pictorialBar',
      symbolSize: [45, 8],
      symbolOffset: [0, 4],
      z: 1,
      itemStyle: {
        color: function (params) {
          return colorBg(params.dataIndex)
        }
      },
      data: tData
    }
  ]
})
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ZionHH

落魄前端,在线炒粉

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

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

打赏作者

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

抵扣说明:

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

余额充值