• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

echart堆叠柱状图,顶部显示堆叠柱总数的

武飞扬头像
hongsir_12
帮助1

学新通
有这么些堆叠柱状图,想要在每个堆叠柱的顶端显示总数,这时我们可以在series里面再push一个bar,这个bar的值为前面柱子数据的总数和,因此高度是等高的。
学新通
记得这个新push的bar的stack属性值是和前面相同同stack的堆叠柱是不同的值,然后设置z为-1,barGap为’-100%’,这样就能够把总计的柱子给隐藏到堆叠柱的后面了。
学新通

代码

//各子公司不同设备工单分布统计表
let data = [
  {公司: '寿险',硬件设备: 5,操作系统: 15,数据库中间件: 25,安全: 5,网络: 9},
  {公司: '健康险',硬件设备: 7,操作系统: 13,数据库中间件: 5,安全: 21,网络: 17},
  {公司: '南中心',硬件设备: 18,操作系统: 28,数据库中间件: 13,安全: 32,网络: 17},
  {公司: '科技运营部',硬件设备: 12,操作系统: 13,数据库中间件: 22,安全: 19,网络: 12},
  {公司: '88号',硬件设备: 21,操作系统: 15,数据库中间件: 10,安全: 5,网络: 6}
];
const deviceList = Object.keys(data[0]).filter((key) => key !== '公司');
const newData = deviceList.map((device) => {
  return {
    设备: device,
    ...Object.fromEntries(data.map((item) => [item['公司'], item[device]])),
    总计:data.map(item=>item[device]).reduce((pre,next)=>{
        pre  = next    
        return pre
    },0)
  };
});
option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  legend: {},
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  dataset: {
    dimensions: ['设备', '寿险', '健康险', '南中心', '科技运营部', '88号','总计'],
    source: newData
  },
  xAxis: [
    {
      type: 'category',
      data: [`硬件设备`, `操作系统`, `数据库中间件`, `安全`, `网络`]
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: '寿险',
      type: 'bar',
      stack: 'Ad',
      barWidth: 30,
      label: {
        show: true,
        position: 'inside',
        fontSize: 15
      },
      emphasis: {
        focus: 'series'
      }
    },
    {
      name: '健康险',
      type: 'bar',
      stack: 'Ad',
      label: {
        show: true,
        position: 'inside',
        fontSize: 15
      },
      emphasis: {
        focus: 'series'
      }
    },
    {
      name: '南中心',
      type: 'bar',
      stack: 'Ad',
      label: {
        show: true,
        position: 'inside',
        fontSize: 15
      },
      emphasis: {
        focus: 'series'
      }
    },
    {
      name: '科技运营部',
      type: 'bar',
      stack: 'Ad',
      label: {
        show: true,
        position: 'inside',
        fontSize: 15
      },
      emphasis: {
        focus: 'series'
      }
    },
    {
      name: '88号',
      type: 'bar',
      barWidth: 30,
      stack: 'Ad',
      label: {
        show: true,
        position: 'inside',
        fontSize: 15
      },
      emphasis: {
        focus: 'series'
      }
    },
    {
      name: '总计',
      type: 'bar',
      stack: '',
      barWidth: 30,
      label: {
        normal: {
          show: true,
          position: 'top',
          color: '#000'
        },
      },
      z: -1,
      //不同系列的柱间距离,为百分比,如果想要两个系列的柱子重叠,可以设置 barGap 为 '-100%'。
      barGap: '-100%',
    }
  ]
};

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhiahjgg
系列文章
更多 icon
同类精品
更多 icon
继续加载