echarts渲染图表

接入接口后拿到数据 渲染图表

<template>
  <div class="sewageStatistics">
    <div class="title">污水来源统计</div>
    <div class="line"></div>
    <div class="sewage">
      <div id="source" class="source"></div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      xData: [],
      yData: [],
    };
  },
  created() {},
  computed: {},
  mounted() {
    this.sewageShow();
    this.getSewageSource();
  },
  methods: {
    getSewageSource() {
      let myChart = this.$echarts.init(document.getElementById("source"));

      this.$store.dispatch("statisticAnalysis/getSewageSource").then((res) => {
        if (res.success) {
          res.result.forEach((item) => {
            this.xData.push(item.label);
            this.yData.push(item.value);
          });
          var option;

          option = {
            tooltip: {},
            xAxis: {
              type: "category",
              data: this.xData,
              splitLine: {
                show: false,
              },
              axisLine: {
                show: false,
              },
              axisTick: {
                show: false,
              },
            },
            yAxis: {
              type: "value",
              splitLine: {
                show: true,
                lineStyle: {
                  type: "dashed",
                },
              },
              // axisLine: {
              //   show: true,
              // },
            },
            series: [
              {
                data: this.yData,
                type: "bar",
                barWidth: "10",
              },
            ],
          };

          option && myChart.setOption(option);
        }
      });
    },
    sewageShow() {},
  },
};
</script>
<style lang="scss" scoped>
.title {
  width: 100%;
  height: 3.25rem;
  font-size: 18px;
  font-weight: 700;
  text-align: left;
  color: #43485a;
  padding-left: 1.6rem;
  padding-top: 1rem;
  box-sizing: border-box;
}
.line {
  width: 100%;
  height: 2px;
  background: #f2f2f2;
}
.sewage {
  width: 45rem;
  height: 21rem;
  padding: 0 1rem 0;
  // background-color: #fff;
  box-sizing: border-box;
  .source {
    width: 100%;
    height: 100%;
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值