Vue Echarts柱形图(带滚动效果)

Vue Echarts柱形图(带滚动效果)

代码

<template>
  <div class="timeLineview">
    <div v-bind:style="{ height: heightData + 'px' }" ref="categoryChart"></div>
    <div v-bind:style="{ height: noHeight + 'px' }" class="nomore">
      {{ noData }}
    </div>
  </div>
</template>

<script>
import echarts from "echarts";
export default {
  components: {},
  name: "timeLine",
  props: {
    question: {}
  },
  data() {
    return {
      datainfo: [],
      datatitle: [],
      chart: null,
      heightData: 300,
      noHeight: 0,
      noData: ""
    };
  },
  methods: {
    resize() {
      this.chart.resize();
    },
    find() {
    //获取数据
      if (this.question) {
        for (let index = 0; index < this.question.length; index++) {
          if (this.question[index].statValue > 0) {
          //y轴
            this.datainfo.push(this.question[index].statValue);
            //X轴
            this.datatitle.push(this.question[index].statLabel);
          }
        }
      }

      this.chart = echarts.init(this.$refs.categoryChart);
      const option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        title: {},
        legend: {},
        dataZoom: [
          {
            type: "slider",
            start: 0,
            end: (100 / this.datainfo.length) * 5   //显示五个
          },
          {
            type: "inside",
            start: 0,
            end: (100 / this.datainfo.length) * 5//显示五个
          }
        ],
        xAxis: {
          data: this.datatitle
        },
        yAxis: { minInterval: 1 },   //显示为整数 最小间距1
        series: [
          {
            type: "bar",
            name: "数量",
            data: this.datainfo,

            itemStyle: {
              color: "#77bef7"
            }
          }
        ]
      };
      this.chart.setOption(option);
      if (this.datainfo.length > 0) {
        this.heightData = 300;
      } else {
        this.heightData = 0;
        this.noHeight = 300;
        this.noData = "暂无数据";
      }
    }
  },
  mounted() {
    this.find();
  },
  created() {}
};
</script>

<style  lang="less" scoped>
.nomore {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
}
</style>

效果图
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值