echarts实现x轴上下的柱图

import * as echarts from 'echarts';

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

let data1 = [320, 302, 341, 374, 120, 132, 101];
let data2 = [390, 450, 420, 134, 190, 230, 210];

option = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  legend: {
    data: ['Profit', 'Expenses', 'Income']
  },
  grid: [
    {
      top: '10%',
      width: '80%',
      height: '40%',
      containLabel: false
    },
    // {
    //     top: '40%',
    //     width: '80%',
    //     height:'20%',

    // },
    {
      top: '50%',
      width: '80%',
      height: '40%',
      containLabel: false
    }
  ],
  xAxis: [
    {
      type: 'category',
      position: 'bottom',
      inverse: false,
      gridIndex: 0,
      axisLabel: {
        show: false // 这里设置不显示x轴名称
      },
      axisTick: {
        show: false // 这里设置为 false 即可去掉 x 轴的刻度线
      }
    },
    {
      type: 'category',
      position: 'top',
      inverse: false,
      gridIndex: 1,
      axisLabel: {
        show: false // 这里设置不显示x轴名称
      },
      axisTick: {
        show: false // 这里设置为 false 即可去掉 x 轴的刻度线
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      gridIndex: 0,
      axisTick: {
        show: false
      }
      // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    {
      gridIndex: 1,
      position: 'center',
      inverse: true,
      axisLabel: {
        show: true,
        // align: 'center',
        // padding: [8, 0, 0, 0],
        fontSize: 12,
        color: `#262C41`
      },
      axisLine: {
        show: false
      }
    }
  ],
  series: [
    {
      name: 'Income',
      type: 'bar',
      xAxisIndex: 0,
      yAxisIndex: 0,
      label: {
        show: true, // 显示数值
        position: 'top' // 数值显示在顶部
      },
      data: [320, 302, 341, 374, 390, 450, 420]
    },
    {
      name: 'Expenses',
      type: 'bar',
      xAxisIndex: 1,
      yAxisIndex: 1,
      label: {
        show: true, // 显示数值
        position: 'bottom' //显示位置
      },
      data: [120, 132, 101, 134, 190, 230, 210]
    }
  ]
};

option && myChart.setOption(option);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

毅争晨夕

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

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

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

打赏作者

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

抵扣说明:

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

余额充值