5

私はd3.jsを初めて使用しますが、使用するd3機能がわかりません。

原点を中心に(円の中に)要素のセットを同心円状に配置する必要があります。

svg.selectAll('circle').each(function() {
    d3.select(this)
        .attr('cx', r * Math.cos(theta))
        .attr('cy', r * Math.sin(theta));
    theta += thetaInc;
});

それで、上記のコードのような退屈なことをする代わりに、これを行うためのd3の短い方法は何ですか?

4

1 に答える 1

9

これを行うd3の方法は、データを渡し、データムのインデックスに基づいて位置を計算することです。

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)); });
于 2013-02-09T22:22:16.993 に答える