echarts 双向柱状图 共用y轴

 

 效果图如下:

 

代码:

const animationDuration = 1500

const barName = ['销售管理部', '生产技术部', '研发部', '质量管理部', '总经办', '采购供应部', '人力资源部', '综合管理部', '财务部']
const rzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]
const lzData= [34, 26, 17, 17, 4, 4, 4, 4, 2]


this.chart.setOption({
        color: ['#2ec7c9', '#ED7D31', '#5ab1ef'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          left: 'center',
          top: '0',
        },
        grid: [
          {
            show: false,
            left: '3%',
            top: '30',
            bottom: '0%',
            containLabel: true,
            width: '38%'
          },
          {
            show: false,
            left: '51.5%',
            top: '30',
            bottom: '6%',
            width: '0%'
          },
          {
            show: false,
            right: '3%',
            top: '30',
            bottom: '0%',
            containLabel: true,
            width: '38%'
          }
        ],
        xAxis: [
          {
            name: '人数',
            type: 'value',
            inverse: true, // 强制设置坐标轴分割间隔
            axisLine: {
              // 坐标轴轴线相关设置
              show: true, // 是否显示坐标轴轴线
              onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
              lineStyle: {
                color: '#ECEDF0'
              }
            },
            axisTick: {
              show: true
            },
            position: 'bottom',
            axisLabel: {
              show: true,
              color: '#c6d3d7',
              fontSize: 12,
              fontFamily: 'DINPro-Regular'
            },
            splitLine: {
              show: false
            }
          },
          {
            gridIndex: 1,
            show: false
          },
          {
            gridIndex: 2,
            axisLine: {
              show: true, // 是否显示坐标轴轴线
              onZero: true, // X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上
              lineStyle: {
                color: '#ECEDF0'
              }
            },
            axisTick: {
              show: true
            },
            position: 'bottom',
            axisLabel: {
              show: true,
              color: '#c6d3d7',
              fontSize: 12,
              fontFamily: 'DINPro-Regular'
            },
            splitLine: {
              show: false
            }
          }
        ],
        yAxis: [
          {
            type: 'category',
            inverse: true,
            position: 'right',
            axisLine: {
              show: true,
              lineStyle: {
                color: '#606266'
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: false
            },
            data: barName
          },
          {
            gridIndex: 1,
            type: 'category',
            inverse: true,
            position: 'left',
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: '#606266',
                fontSize: 12,
                fontFamily: 'pmzd_title'
              },
              align: 'center'
            },
            data: barName.map(function(value) {
              return {
                value: value,
                textStyle: {
                  align: 'center'
                }
              }
            })
          },
          {
            gridIndex: 2,
            type: 'category',
            inverse: true,
            position: 'left',
            axisLine: {
              show: true,
              lineStyle: {
                color: '#606266'
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: false
            },
            data: barName
          }
        ],
        series: [
          {
            name: '入职',
            type: 'bar',
            itemStyle: {
              normal: {
                label: {
                  show: true, // 开启显示
                  position: 'left', // 在上方显示
                  textStyle: {
                    // 数值样式
                    // color: colors[0].borderColor,
                    color: '#606266',
                    fontSize: 12
                  }
                },
                borderWidth: 1
              }
            },
            data: rzData,
            animationDuration
          },
          {
            name: '离职',
            type: 'bar',
            xAxisIndex: 2,
            yAxisIndex: 2,
            itemStyle: {
              normal: {
                label: {
                  show: true, // 开启显示
                  position: 'right', // 在上方显示
                  textStyle: {
                    // 数值样式
                    color: '#606266',
                    fontSize: 12
                  },
                },
                borderWidth: 1
              }
            },
            data: lzData,
            animationDuration
          }
        ]
      })

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值