D3.js 使用d3js计算力布局中闭合空间的面积时出错
我有一张用force布局绘制的图表。基本上,我想给图表中循环中包含的区域上色。这是我的 当部队的布局稳定下来时,我正试图画周期D3.js 使用d3js计算力布局中闭合空间的面积时出错,d3.js,force-layout,D3.js,Force Layout,我有一张用force布局绘制的图表。基本上,我想给图表中循环中包含的区域上色。这是我的 当部队的布局稳定下来时,我正试图画周期 force.on("tick",function(){ // ... I update the position of nodes and the links if(force.alpha() < 0.006){ force.stop(); // I dont know if there's an easier
force.on("tick",function(){
// ... I update the position of nodes and the links
if(force.alpha() < 0.006){
force.stop();
// I dont know if there's an easier way of doing this
var xnodes = [];
force.nodes().forEach(function(d){
xnodes.push([d.x, d.y]);
});
// I tried creating a path and filling with with green
vis.select("path.area")
.data([xnodes])
.enter().append("path")
.style("fill", "#00ff00")
.attr("class", "area")
.attr("svg:d", d3.svg.area());
}
});
但是,当我在包含必要的库之后将此代码放在一个空白html文件中时,它工作得很好。它确实绘制了一条路径并用绿色填充。我真的很困惑。任何帮助都将不胜感激。谢谢。代码链接指向一个没有javascript的小提琴。很抱歉。现在该起床了。谢谢你指出。对不起,不是。您必须单击jsfiddle上的update,然后根据版本号复制粘贴新的url,最后添加/2
var ynodes = [[352.3554660996234,304.3361316660001],[449.88953454311286,313.14153937680953],
[392.0458559272036,389.6656922220398],[352.3554660996234,304.3361316660001]];
vis.select("path.area")
.data([ynodes])
.enter().append("path")
.style("fill", "#00ff00")
.attr("class", "area")
.attr("svg:d", d3.svg.area());