【发布时间】:2014-09-23 05:43:38
【问题描述】:
所以,我尝试关注 Jason Davies 对Circle clip and projection with D3 orthographic 线程的回答...
我尝试了 3 种不同的可能性:
svg.append("g").attr("class","points")
.selectAll("path")
.data(places.features)
.enter()
.append("path")
//THIS COMMENTED PART DOES NOT WORK
//though the console spits out an array
/*.datum(function(d){
console.log(d.geometry.coordinates)
return d3.geo.circle()
.origin(d.geometry.coordinates)
.angle(2)
})*/
//THIS UNCOMMENTED PART WORKS
//and places the circles accordingly with a fixed size radius
.datum(d3.geo.circle()
.origin(function(d){return d.geometry.coordinates})
.angle(2)
)
//THIS COMMENTED PART DOES NOT WORK
//which is a shame, as my goal is to change the angle of each circle
/*.datum(d3.geo.circle()
.origin(function(d){return d.geometry.coordinates})
.angle(function(d){return 2})
)*/
.attr("class", "point")
.attr("d", path)
如何使最后评论的部分生效,以便更改圆的半径?非常感谢。
【问题讨论】:
-
您能否详细说明它是如何不起作用的?任何错误信息?会发生什么,您预计会发生什么?
-
它是如何不起作用的:圈子只是没有创建......第一个评论部分没有给我任何消息错误。第二个评论部分说:“Uncaught TypeError: Cannot read property '0' of undefined” 我只是想弄清楚为什么我不能在我的角度属性中放置一个返回函数。
-
你需要一个
function(d),就在.datum()之后,就像第一个评论部分一样。 -
我知道了 .datum(function(d){ var origin = d.geometry.coordinates var angle = avions[d.properties.index].total_morts/100 return d3.geo.circle() .angle(angle).origin(origin)() } ) 这行得通!诀窍在最后的括号中。为什么会这样呢??
-
哦,对了,没看到——
d3.geo.circle()是一个工厂函数(即返回函数的函数),您仍然需要调用它。
标签: d3.js