Echarts 阶梯瀑布图 从负数增长到正数 和 从正数减少到负数 效果实现

当要求从-30增长60到30时候,这个瀑布图如何实现?
在这里插入图片描述
最终实现效果如上图所示,直接看代码:

option = {
  title: {
    text: 'Accumulated Waterfall Chart'
  },
  legend: {
    data: ['Expenses', 'Income']
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    data: (function () {
      let list = [];
      for (let i = 1; i <= 11; i++) {
        list.push('Nov ' + i);
      }
      return list;
    })()
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      name: 'Placeholder',
      type: 'bar',
      stack: 'Total',
      itemStyle: {
        borderColor: 'transparent',
        color: 'transparent'
      },
      emphasis: {
        itemStyle: {
          borderColor: 'transparent',
          color: 'transparent'
        }
      },
      data: [0, 0]
    },
    {
      name: 'Income',
      type: 'bar',
      stack: 'Total',
      label: {
        show: false,
        position: 'top'
      },
      data: [-30, '-']
    },
    {
      name: 'Expenses',
      type: 'bar',
      stack: 'Total',
      label: {
        show: false,
        position: 'bottom'
      },
      data: ['-', 30]
    },
      {
      name: 'Expenses',
      type: 'bar',
      stack: 'Total',
      label: {
        show: false,
        position: 'bottom'
      },
      data: ['-', -30]
    }
  ]
};

主要思路就是:一列展示用两个bar柱状图来展示!要记得当要实现跨x轴增长或减少的时候,总数累计部分要设置成0,然后用两个bar,一个是-30,另一个是30,这样就能实现跨x轴的瀑布效果!!
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

这里是杨杨吖

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

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

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

打赏作者

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

抵扣说明:

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

余额充值