欢迎来到BlackTest-老王自动化测试

vue动态生成多个Echarts图表

1.动态循环id

<div v-for="(item,index) in chartList" :key="index">
      <div :id="`chart${index}`"></div>
</div>

 

2.js部分

1
2
3
4
5
6
this.chartList = res.data.data.chartList;//从后台获取数据
if (this.chartList.length > 0) {
  this.$nextTick(() => {
    this.initChart()
  })
}

  

 

1
2
3
4
5
6
7
8
initChart() {
    this.chartList.forEach((val, index) => {
      const myChart = this.$echarts.init( document.getElementById(`chart${index}`))
      //注意this.chartList[index]这是我们后台拼好数据直接set就行了
      myChart.setOption(this.chartList[index])
    })
  }
},

  



posted @   BlackTest  阅读(1139)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示