Vue项目中ECharts图表不显示问题

相关文章:

ECharts官网

在Vue项目中使用ECharts


最近在工作中需要使用ECharts绘制图表,所以根据参考文档尝试了一番,遇到了图表不显示的问题。
在这里插入图片描述
后来参考了网上许多解决方案,最终发现,原来是因为自己没给图表组件设置height。现记录如下:

<ability-line style="width:100%;height:300px;"></ability-line>

ability-line不是ECharts封装组件,是自己编写的组件,需要使用imports导入并使用components映射成组件,其代码如下:

<template>
  <div id="ve-histogram"></div>
</template>

<script>
export default {
  data() {
    return {
      options: {
        color: ['#ffdf25', '#36a9ce', '#d0e17d'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '0%',
          right: '0%',
          bottom: '10%',
          top: '10%',
          containLabel: true
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            axisTick: { show: false },
            data: ['1月', '2月', '3月']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '全国平均业绩',
            type: 'bar',
            barGap: 0,
            data: [320, 332, 301]
          },
          {
            name: '地区平均业绩',
            type: 'bar',
            data: [220, 182, 191]
          },
          {
            name: '业务员业绩',
            type: 'bar',
            data: [150, 232, 201]
          }
        ]
      }
    };
  },
  mounted() {
    const dom = document.getElementById('ve-histogram');
    if (dom.getAttribute('_echarts_instance_') !== null) {
      this.chart = this.$echarts.getInstanceByDom(dom);
      this.chart.setOption({}, true);
    } else {
      this.chart = this.$echarts.init(dom);
    }
    this.$nextTick(() => {
      this.chart.setOption(this.options, true);
    });
    window.addEventListener('resize', () => {
      this.chart.resize();
    });
  }
};
</script>
<style scoped>

</style>

问题解决:
在这里插入图片描述

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

只爭朝夕不負韶華

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

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

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

打赏作者

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

抵扣说明:

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

余额充值