0
我有以下2個代碼片段。我想知道爲什麼第二個人不會生成四個圈子?D3中的圓圈選擇
這一個會產生四個圓圈。
var sampleSVG = d3.select("#viz")
.append("svg")
.attr("width", 500)
.attr("height", 500);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 80).attr("cy", 70);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 140).attr("cy", 130);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 200).attr("cy", 190);
var circle = sampleSVG.selectAll("circle").data([32, 57, 112, 293]);
var enter = circle.enter().append("circle");
enter.attr("cy", 90)
.attr("cx", 160)
.attr("r", function(d){return Math.sqrt(d);});
circle.style("fill", "steelblue");
這一個不會產生四個圓圈。只顯示三個圓圈。
var sampleSVG = d3.select("#viz")
.append("svg")
.attr("width", 500)
.attr("height", 500);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 80).attr("cy", 70);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 140).attr("cy", 130);
sampleSVG.append("circle").style("stroke", "gray").style("fill", "white").attr("r", 10).attr.("cx", 200).attr("cy", 190);
var circle = sampleSVG.selectAll("circle");
circle.data([32, 57, 112, 293]);
var enter = circle.enter().append("circle");
enter.attr("cy", 90)
.attr("cx", 160)
.attr("r", function(d){return Math.sqrt(d);});
circle.style("fill", "steelblue");
我不知道他們爲什麼會有不同的結果。 shoudn't var circle = sampleSVG.selectAll(「circle」)。data([32,57,112,293]);與相同var circle = sampleSVG.selectAll(「circle」); circle.data([32,57,112,293]);?
有你。只是將其更改爲:circle = circle.data([32,57,112,293]); – whileone