utworzyć grupę z 9 elementów (kółka), takich jak:d3js: Jak wybrać n-ty element grupy?
// JS
var data=[ 1,2,3,4,5,6,7,8,9 ];
var svg = d3.select("body").append("svg");
var circles = svg.append("g").attr("id", "groupOfCircles")
.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", function(d){ return d*20;})
.attr("cy", function(d){ return d*10;})
.attr("r" , function(d){ return d;})
.attr("fill","green");
//xml
<svg>
<g id="groupOfCircles">
<circle cx="20" cy="10" r="1" fill="green"></circle>
<circle cx="40" cy="20" r="2" fill="green"></circle>
<circle cx="60" cy="30" r="3" fill="green"></circle>
<circle cx="80" cy="40" r="4" fill="green"></circle>
<circle cx="100" cy="50" r="5" fill="green"></circle>
<circle cx="120" cy="60" r="6" fill="green"></circle>
<circle cx="140" cy="70" r="7" fill="green"></circle>
<circle cx="160" cy="80" r="8" fill="green"></circle>
<circle cx="180" cy="90" r="9" fill="green"></circle>
</g>
</svg>
Ale Jak wybrać element n-ty (tj: 3rd okrąg) grupy groupOfCircles
chwilę nie znając wartości identyfikatorów lub atrybutów kręgów?
Będę później pętli nad wszystkimi elementami za pośrednictwem pętli for i kolor każdy na jedną sekundę.
Uwaga: Próbowałem rzeczy, takich jak:
circles[3].attr("fill","red") // not working
d3.select("#groupOfCircles:nth-child(3)").attr("fill","red") // not working
..
Dzięki Lars, powinienem przejrzeć moje klasyki CSS! – Hugolpz
Co powiecie na d3 v4? Nie możesz już wykonywać 'kręgów [0] [4]'. – hobbes3
Ustawienia wewnętrzne uległy zmianie, ale nadal możesz to zrobić: 'circles._groups [0] [4]'. –