d3.js甜甜圈图::其他路径被渲染而不更新
d3.js doughnut chart :: Additional paths are rendered and not updated
我在d3中渲染甜甜圈图时遇到问题。我有两个甜甜圈,我正在为每个函数并排创建:
data.forEach(function(d,i){...}
图表渲染得很好。当我去更新图表时,路径会被重新绘制。不确定为什么会发生这种情况,因为我正在使用.enter()
有什么建议吗?
var singleDonutData = [1];
var donutSections=singleDonut.selectAll(".donutSections")
.data(singleDonutData)
.enter()
.append("g")
.attr("class","donutSections");
var pathGroup = svg.select("." + donutName).select(".donutSections").selectAll("path.arc")
.data(pie(d));
var path = pathGroup
.enter()
.append('path')
.style('fill', function(d){ //give arc a color in SVG Scale
return color(d.data.label);
})
.attr("d", arc)
.each(function(d) { this._current = d; }); // store the initial angles;
您需要在生成的路径上添加相应的类名,例如:
var pathGroup = svg.select("." + donutName).select(".donutSections").selectAll("path.arc")
.data(pie(d));
var path = pathGroup
.enter()
.append('path')
.style('fill', function(d){
return color(d.data.label);
})
.attr("class", "arc") // corresponding to selectAll("path.arc")
.attr("d", arc)
.each(function(d) { this._current = d; }); angles;
以便在更新图表时,d3可以正确地选择这些已经渲染的路径。
更新后,您还需要添加代码来处理更新选择。类似这样的东西:
pathGroup.transition().duration(1000)
.attrTween("d", function(d){
// some transition animation code here if you need it.
})
相关文章:
- 如何在编译时更新yeoman angular中的html路径
- 将URL路径与<a>attr('href')来动态更新.active类
- 不可变,更新在给出无效的键路径
- D3 在更新时调整路径大小(获得 10 像素宽度) - 为什么
- 当更新流星中的嵌套集合时,如何为更新路径传递变量
- 如何使用jQueryURI更新具有完整目录路径的链接
- 如何在Angular文件上传模块中更新URL路径
- 在嵌套json对象中查找和更新,而不更改不同子路径中的相同密钥对值
- 由于斜杠字符,Firebase多路径更新失败
- d3.js甜甜圈图::其他路径被渲染而不更新
- 使用路径线选择更新图案
- 具有多个更新路径的主干用户模型
- FabricJS:如何获取更新路径的位置
- 避免无效路径格式错误在D3更新
- 从类型化数组更新svg路径
- 使用HTML文本字段沿着SVG文本路径更新文本
- 如何隐藏路径位置,当使用外部Javascript更新HTML与外部文本文档
- 在树的顶部绘制SVG路径.无法更新路径
- 要求 JS填充程序在更新路径后丢失
- RaphaelJS/Javascript更新路径,而不是创建新的