admin管理员组文章数量:1316824
I am new to d3.js and not sure which d3 functionality to use.
I need to place a set of elements concentrically about an origin (in a circle).
svg.selectAll('circle').each(function() {
d3.select(this)
.attr('cx', r * Math.cos(theta))
.attr('cy', r * Math.sin(theta));
theta += thetaInc;
});
So instead of doing something tedious like the above code, what is the d3 short way of doing this?
I am new to d3.js and not sure which d3 functionality to use.
I need to place a set of elements concentrically about an origin (in a circle).
svg.selectAll('circle').each(function() {
d3.select(this)
.attr('cx', r * Math.cos(theta))
.attr('cy', r * Math.sin(theta));
theta += thetaInc;
});
So instead of doing something tedious like the above code, what is the d3 short way of doing this?
Share Improve this question asked Feb 9, 2013 at 19:33 Blake RegaliaBlake Regalia 2,7662 gold badges21 silver badges29 bronze badges1 Answer
Reset to default 9The d3 way to do this would be to pass in the data and calculate the positions based on the index of the datum, i.e. something like
var theta = 2 * Math.PI / array.length;
svg.selectAll('circle').data(array).enter()
.append("circle")
.attr('cx', function(d, i) { return(r * Math.cos(i * theta)); })
.attr('cy', function(d, i) { return(r * Math.sin(i * theta)); });
本文标签: javascriptd3js Plot elements using polar coordinatesStack Overflow
版权声明:本文标题:javascript - d3.js Plot elements using polar coordinates - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741973148a2407959.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论