admin管理员组文章数量:1292119
Here is the plunker -
Is it logging right values, but not building pie chart.
Instead, I can see the following in logs
nvd pie - {"values":[{"parent":"Food","amount":116.1},{"parent":"Home","amount":670.14},{"parent":"Travel","amount":365.24},{"parent":"Taxes","amount":31.240000000000002},{"parent":"Entertainment","amount":13.24}]} script.js:166
Uncaught TypeError: Cannot call method 'map' of undefined nv.d3.js:9623
How can I fix this issue?
Here is the plunker - http://plnkr.co/edit/pXitfqb8K2IbxOHXw0uL?p=preview
Is it logging right values, but not building pie chart.
Instead, I can see the following in logs
nvd pie - {"values":[{"parent":"Food","amount":116.1},{"parent":"Home","amount":670.14},{"parent":"Travel","amount":365.24},{"parent":"Taxes","amount":31.240000000000002},{"parent":"Entertainment","amount":13.24}]} script.js:166
Uncaught TypeError: Cannot call method 'map' of undefined nv.d3.js:9623
How can I fix this issue?
Share Improve this question asked Jun 17, 2013 at 21:57 daydreamerdaydreamer 92.1k204 gold badges472 silver badges750 bronze badges3 Answers
Reset to default 4Having a look at line 9623 from nv.d3.js, you will find that the map method is called on the first element of an array and your data is an object.
What you need to do, is to encapsulate your values inside of a 1 element array:
var data = [{
key : "",
values : [{"parent":"Food","amount":116.1},{"parent":"Home","amount":670.14},{"parent":"Travel","amount":365.24},{"parent":"Taxes","amount":31.240000000000002},{"parent":"Entertainment","amount":13.24}]
}];
I struggled with this for a while, mainly because I started from the live examples on the nvd3 site.
It turns out the data format in the examples on the live site differs to that in the examples bundled with the core nvd3 download.
In the pie.html example in the download the data is specified as follows:
var testdata = [
{
key: "One",
y: 5
},
{
key: "Two",
y: 2
},
{
key: "Three",
y: 9
}
];
Then when passing the data through it's wrapped in an unnamed/keyed array ...
d3...datum([testdata])....
This format works fine for me.
After struggling through many hours, I was able to fix this issue.
Please look at http://plnkr.co/edit/qJnZzBS4ZOUtD2q9FV11?p=preview to see how it works
版权声明:本文标题:javascript - nvd3 pie chart says Uncaught TypeError: Cannot call method 'map' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741546871a2384644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论