javascript - nvd3 饼图显示 Uncaught TypeError : Cannot call method 'map' of undefined

标签 javascript d3.js nvd3.js

这是 plunker - http://plnkr.co/edit/pXitfqb8K2IbxOHXw0uL?p=preview

它是否记录了正确的值,但没有构建饼图。
相反,我可以在日志中看到以下内容

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

我该如何解决这个问题?

最佳答案

查看 nv.d3.js 的第 9623 行,您会发现在数组的第一个元素上调用了 map 方法,并且您的数据是一个对象。

您需要做的是将您的值封装在一个 1 元素数组中:

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}] 
}];

关于javascript - nvd3 饼图显示 Uncaught TypeError : Cannot call method 'map' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17157554/

相关文章:

javascript - 在 BigQuery 中将 API 调用作为 UDF 的一部分 - 可能吗?

javascript - Angular - 将 ng Strict 与 Google Chart 库一起使用

javascript - 如何删除 d3.js 中的现有节点

javascript - nvd3 LineChart 工具提示不起作用

javascript - 将子项拆分为第 n 行,每行包含特定数量的子项

javascript - 如何合并两个json对象?

javascript - 在 THREE.JS 中手动对 Matrix4 应用旋转和平移

javascript - 使用 d3.js (v5) 读取没有标题的 csv

javascript - 动态更新平行坐标数据

javascript - 使用 $.getJson 分配变量