后端数据 动态修改Echarts

获取到后端数据

  基于y轴的柱状图,

for 循环 赋值拿到的数据,要放在data 中, 方便 options 配置中使用

 initChart() {
 >> 柱状图
      this.chart = this.$echarts.init(this.$refs.refchart);
      getbizcount("11320722014281341M").then(res=>  {
        this.bizChart=res.data.data
        console.log(  this.bizChart)

        for (let i = 0; i < this.bizChart.length; i++) {
           this.datay[i] = this.bizChart[i].name  // 拿到 展示的name
            this.serData[i]= this.bizChart[i].count     // 具体数据
          // console.log(this.bizChart[i].name)
        }
    
            // 初始化图表配置
            var option = {
        xAxis: {
          type: "value",
          show: false,
        },
        yAxis: { 
                      axisLabel:{
          //                 width: 100,//将内容的宽度固定
          // overflow: 'truncate',//超出的部分截断
          // // truncate: '...',//截断的部分用...代替
                      },
          show: true,
          axisLine: {
            show: false,
            lineStyle: {
              width: 2, // 轴线宽度
            },
          },
          axisTick: {
            show: false,
          },
          textStyle: {
            fontSize: "10",
          },
          axisLabel: {
            textStyle: {
              width: 60, //将内容的宽度固定
          overflow: 'truncate',//超出的部分截断
              color: "#fff",
            },
          },
          lineStyle: {
            color: "yellow",
            type: "solid", //y轴线为实线
          },
          type: "category",
          data:  this.datay, // 展示的name数据
        },
        series: [
          {
            // barWidth: 8, // 柱图宽度
            // barGap: 36, // 柱图之间的间距
            grid: {
              containLabel: true,
              top: 30,
              left: 10,
              right: 10,
              bottom: 8,
            },
            color: "#0BDEDB",
            data:this.serData, // 具体数据
            type: "bar",
            label: {
              show: true, // 开启显示
              position: "right", // 在上方显示
              distance: 10, // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。
              verticalAlign: "middle",
              textStyle: {
                // 数值样式
                color: "#fff",
                fontSize: 10,
              },
              // formatter: function (params) {
              //   return params.value + "%";
              // },
            },
          },
        ],
      };
      this.chart.setOption(option);
      
      
      
      
      
      
    }) 


    },

渲染出来的。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值