vue2中使用echarts

1.安装  :  npm install echarts --save

2、在main.js中引入echarts  

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

3.页面中使用

 

<template>

  <!-- 合同类型 -->
  <div class="echarts">
    <div v-if="pieData.length==0">
      //没有值的时候显示
      <h4>合同地域分布</h4>
      <el-empty description="暂无数据" :image="require('../../assets/png/缺省图 (1)暂无代办.png')"></el-empty>
    </div>
    <template v-else>
      <div class="pie" ref="pie" style="width: 100%; height: 350px"></div>
    </template>
  </div>
</template>


<script>
//引入接口
import {
  incomeStatistics, //收入统计
  contractLineChart, //合同折线图
  contractArealDistribution, //合同地域分布
} from "@/api/other/contract.js";


export default {
  data () {
    return {
      pieData: [], //饼图
    }
  },
  created () {
    this.getPie(); //地域饼状图

    //方法一:created()延迟加载getChart方法,先加载dom,否则会报错
    //方法二:使用mounted()挂载
    setTimeout(() => {
      this.inOrigin(); // 地域分布
    }, 2000);
  },
  mounted () {
  },
  methods: {


    // 地域饼状图
    inOrigin () {
      let myChart = this.$echarts.init(this.$refs.pie);
      // 地域分布---圆形饼状图
      let optionPie = {
        tooltip: {
          trigger: 'item',
        },
        title: {
          show: true,
          text: "地域分布",
          textStyle: {
            fontSize: 16,
            fontweight: 600,
            color: ' #292B33',
          },
        },
        legend: {
          orient: "horizontal",
          icon: "circle",
          itemHeight: 8,
          itemWidth: 8,
          bottom: "15%",
          left: "0% ",
        },

        color: ["#5B8FF9", "#00CCCC ", "#F6BD16 ", "##FF3343", "#9661BC"],
        series: [{
          // name: "Access From",
          type: 'pie',
          radius: ['20%', '45%'],
          center: ['50%', '45%'],
          // roseType: 'area',
          // 鼠标悬浮
          animation: false,
          avoidLabelOverlap: false,
          //  取消牵引线
          label: {
            normal: {
              show: false,
            },
          },
          labelLine: {
            normal: {
              show: false
            }
          },
          // label: {
          //   formatter: "{c}",
          // },
          data: this.pieData,
        },],
      };
      //图标自适应
      let listener = function () {
        myChart.resize()
      }
      window.addEventListener('resize', listener)
      //图标自适应
      myChart.setOption(optionPie);
    },
    // 接口--地域饼状图
    getPie () {
      contractArealDistribution().then((res) => {
        let data = res.data;
        for (let i = 0; i < data.length; i++) {
          this.pieData.push({
            value: data[i].contractQuantity,
            name: data[i].province,
          });
        }
      });
    },

  },
}
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值