Vue使用Echarts避免踩坑

将Axios请求到的数据直接设置到data中的图表会报错,要么放到axios的响应中,要么在axios响应中调用生成echarts图

methods: {
  // 交易总笔数
  getdashboardData() {
    dashboardData().then((result) => {
      if (result.code == 0) {
        this.totalLoanAmount = result.data.totalLoanAmount;
        this.totalRepayAmount = result.data.totalRepayAmount;
        this.totalAmountReceived = result.data.totalAmountReceived;

        for (var i = 0; i < result.data.countryData.length; i++) {
          result.data.countryData[i].value =
            result.data.countryData[i].loanAmount;
          result.data.countryData[i].name = result.data.countryData[i].code;
          delete result.data.countryData[i].loanAmount;
          delete result.data.countryData[i].code;
          this.xdata[i] = result.data.countryData[i].name;
          this.ydata[i] = result.data.countryData[i].value;
        }
        this.countryLoanData.series[0].data = result.data.countryData;

        this.chart = Chart.init(this.$refs.loanEcharts);
        this.chart.setOption(this.countryLoanData);
        this.getSUM();
      }
    });
  },
  // 各个国家贷款统计柱形图
  getSUM() {
    let lwndArr = [];
    let lwtsArr = [];
    lwndArr = this.xdata
    lwtsArr = this.ydata
    const countryLoanDataColumn = {
      gird:{
          left:'10%',
          right:'4%',
          bottom:'3%',
          containLabel:true
      },
      legend:{
        title:"各国家贷款总金额"
      },
      xAxis: {
        name:"国家",
        type: "category",
        data: lwndArr,
      },
      yAxis: {
        type: "value",
        name:"贷款金额"
      },
      series: [
        {
          data: lwtsArr,
          type: "bar",
          label:{
            show:true,
            position:'top'
          }
        },
      ],
    };
    console.log("@",countryLoanDataColumn)
    Chart.init(this.$refs.loanEcharts2).setOption(countryLoanDataColumn,true);
  },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值