echarts 柱状图 x轴数据某个值为空时就会出现柱状图不显示并且占位现象

解决方案:添加多个x轴或者y轴

关键代码:

option = {
  legend: {},
  tooltip: {},
  xAxis: { type: 'value', name: '点击量' },
  yAxis: [
    // 多个y轴!!!!!
    {
      type: 'category',
      name: '页面',
      position: 'left',
      data: ['传输界面', '','']
    },
    { type: 'category', name: '页面', position: 'left', data: ['', '页面',''] },
    {
      type: 'category',
      name: '页面',
      position: 'left',
      data: ['', '', '我的空间']
    }
  ],
  series: [
    {
      type: 'bar',
      name: '传输界面.更多按钮-1111',
      stack: '传输界面.更多按钮',
      emphasis: { focus: 'series' },
      // 设置显示的位置!!!!!!
      yAxisIndex: 0,
      data: [1, '', '']
    },
    {
      type: 'bar',
      name: '主页.tab页-1111',
      stack: '主页.tab页',
      emphasis: { focus: 'series' },
      yAxisIndex: 1,
      data: ['', 9, '']
    },
    {
      type: 'bar',
      name: '主页.tab页-222',
      stack: '主页.tab页',
      emphasis: { focus: 'series' },
      yAxisIndex: 1,
      data: ['', 1, '']
    },
    {
      type: 'bar',
      name: '主页.更多按钮-1111',
      stack: '主页.更多按钮',
      emphasis: { focus: 'series' },
      yAxisIndex: 1,
      data: ['', 4, '']
    },
    {
      type: 'bar',
      name: '我的空间.更多按钮-1111',
      stack: '我的空间.更多按钮',
      emphasis: { focus: 'series' },
      yAxisIndex: 2,
      data: ['', '', 2]
    }
  ]
};

参考链接:

echarts 柱状图 x轴数据为0占位情况 多X轴展示_echarts柱状图两组数据 其中一组为空数据依然占据位置-CSDN博客

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐