我正在尝试呈现来自react-google-charts https://rakannimer.github.io/react-google-charts/#/examples/ColumnChart?_k=xit9kl的ColumnChart
渲染时,控制台记录错误:
Unhandled rejection Error: Failed to set DataTable from data props !和
Uncaught TypeError: this.dataTable.getNumberOfRows is not a function我相信我的道具格式是正确的。
<Chart
chartType='ColumnChart'
data={this.formatData()}
graph_id=''
width='100%'
height='500px'
legend_toggle
/>formatData()返回以下数据结构...
Array[2]
0:Array[3]
0:"Crime Category"
1:Array[63]
2:Object
1:Array[33]
0:Array[65]
0:"Vikings"
1:0
2:0
3:0
4:0
5:7
...这似乎完全符合文档中规定的数据结构,如下所示……
"data":[
[
"Genre",
"Fantasy & Sci Fi",
"Romance",
"Mystery/Crime",
"General",
"Western",
"Literature",
{"role":"annotation"}
],
["2010",10,24,20,32,18,5,""],
["2020",16,22,23,30,16,9,""],
["2030",28,19,29,30,12,13,""]
]发布于 2017-03-05 03:36:28
我读错了数据结构。通过返回所有项的数组,而不是返回两个项的数组,并将其余属性嵌套在其中,解决了该问题。这是工作代码..。
const columns = teamList.map(team => {
const newArray = Object.keys(team['teamCrimeCategorySum'])
.sort()
.map(key => {
return team['teamCrimeCategorySum'][key]
})
return [`${team.name}`, ...newArray, '']
})
return [
[
'Crime Category',
...categories.map(category => `${category.name}`),
{'role':'annotation'}
],
...columns
]发布于 2018-01-17 05:14:22
我也有这个问题,原因略有不同,所以我想我应该加上这个,以防其他人遇到这个问题:
我的数据是这样的:
data = [["Room 524", 50], ["Room 123", 23], ["Room 523", 17], ["Room 964", 12], ["Room 012", 56], ["Room 125", 35]]
在标题行中添加已修复此问题。
data = [["Title A", "Title B"], ["Room 524", 50], ["Room 123", 23], ["Room 523", 17], ["Room 964", 12], ["Room 012", 56], ["Room 125", 35]];
https://stackoverflow.com/questions/42591253
复制相似问题