(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0:
listContent: Array(2)
0: {id: 1, content: "数量", resultCount: 5个}
1: {id: 2, content: "数量2", resultCount: 6个}
length: 2
__proto__: Array(0)
type: 1
typeName: "图表1"
__proto__: Object
1: {type: 2, typeName: "图表2", listContent: Array(3)}
2: {type: 3, typeName: "图表3", listContent: Array(4)}
3: {type: 4, typeName: "图表4", listContent: Array(3)}
- 后台返回10个数组,每个数组对应一个图表,上图有详细数据结构,我怎么遍历这个数组拿到值渲染出10个图表,
大佬们帮我看看
下面是我写的遍历的方法:
if(info.staut == 0){
一次性取10个图表就有错
console.log(info.data) // 数组(length为10)
info.data.forEach((i,index) => {
this.disableCategoryRatoData[index] = []
this.disableCategoryRatoType[index] = []
this.allValuaPortName[index] = i.typeName
i.listContent.forEach(tem => {
console.log(index)
this.disableCategoryRatoData[index].push(tem.resultCount)
this.disableCategoryRatoType[index].push(tem.content)
})
})
注释代码:是我取第5个图表渲染能成功
// this.allValuaPortName= info.data[5].typeName
// info.data[5].listContent.forEach(item => {
// this.disableCategoryRatoData.push(item.resultCount)
// this.disableCategoryRatoType.push(item.content)
// });
}
更新下: html代码部分
图表渲染是封装的,数据直接赋值上去就可以的,但要生成对应下标个数的disableCategoryRatoData数组赋值
<Bar :chartType="this.disableCategoryRatoType" :chartData="disableCategoryRatoData" :chartColor="disableCategoryRatoColor" :chartTitle="allValuaPortName"></Bar>
使用echarts展示,你是不是要这种数组?
补充,如何调用:
这样不是更简单吗。。。
补充
resultCount要为数字类型