我正在使用嵌套数据集和以下代码在 d3 v5 中绘制圆圈:
const scatterGroup = svg.selectAll(".scatterGroup").data(data);
scatterGroup.exit().remove();
scatterGroup
.enter()
.append("g")
.attr("class", "scatterGroup")
.attr("fill", (d, i) => color[i])
.attr("stroke", (d, i) => color[i])
.append("g")
.attr("class", "scatterPoints");
const scatterPoints = scatterGroup
.selectAll(".scatterPoints")
.data((d) => d);
scatterPoints
.enter()
.append("circle")
.attr("class", "scatterPoints")
.attr("cx", (d, i) => xScale(d.x))
.attr("cy", (d, i) => yScale(d.y))
.attr("r", 5);
scatterPoints.exit().remove();
const scatterUpdate = scatterGroup
.transition()
.duration(500)
.attr("fill", (d, i) => color[i])
.attr("stroke", (d, i) => color[i]);
scatterPoints
.transition()
.duration(500)
.attr("cx", (d, i) => xScale(d.x))
.attr("cy", (d, i) => yScale(d.y));
在提供数据的第一次运行中没有任何反应。控件在第一次加载时未到达追加圆圈。第二次加载数据时,d3 附加圆圈。谁能告诉我如何在首次提供数据时让它们出现以及为什么会这样?
神不在的星期二
慕尼黑的夜晚无繁华
随时随地看视频慕课网APP
相关分类