d3.js:如何使用地图功能? [英] d3.js: how to use map function?
本文介绍了d3.js:如何使用地图功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 d3.map()
从以下数组中获取 [10,12]
?
How can I use d3.map()
to get [10, 12]
out of the following array?
var mydata = [
{ '__data__' : 10 },
{'__data__' : 12 }
];
我一直在尝试这个,但它不起作用:
I have been trying this, but it doesn't work:
var mymap = d3.map(mydata, function(d) {
return d.__data__;
});
推荐答案
你不能 - d3.map()
不是用于在数组中映射函数,而是用于散列的垫片。简而言之,虽然可以像散列一样使用对象,但是有些情况可能会发生意外行为。一个新的Javascript标准提出了一个解决方案,在实现之前, d3.map()
可以用于相同的效果。
You can't -- d3.map()
isn't for mapping a function across an array, but a shim for hashes. Briefly, while objects can be used like hashes, there are situations when unexpected behaviour can occur. A new Javascript standard proposes a solution to this, and until it is implemented, d3.map()
can be used to the same effect.
文档中的更多信息。
这篇关于d3.js:如何使用地图功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文