admin管理员组文章数量:1278788
I am having a problem with d3.js with the cluster. It gives me the following error:
Error: Invalid value for attribute transform="translate(undefined,undefined)"
And I have no idea why this gives it to me.
Code:
var loadd3 = function () {
function elbow(d, i) {
return "M" + (d.source.y + 100) + "," + d.source.x + "V" + d.target.x + "H" + (d.target.y + 100);
}
var width = (window.innerWidth - 100),
height = (window.innerHeight - 20);
var cluster = d3.layout.cluster()
.size([height, width - 160]);
var diagonal = d3.svg.diagonal()
.projection(function (d) {
return [d.y, d.x];
});
d3.select("svg").remove();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(40,0)");
var root = dataSource;
var nodes = cluster.nodes(root),
links = cluster.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function (d) {
return "translate(" + d.y + "," + d.x + ")";
})
node.append("rect")
.attr("width", 120)
.attr("height", 60)
.attr("y", -30)
.attr("rx", 5)
.attr("ry", 5);
node.append("rect")
.attr("class", "header")
.attr("width", 120)
.attr("height", 10)
.attr("y", -30)
.attr("rx", 5)
.attr("ry", 5);
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", -6)
.attr("class", function (d) {
return d.children ? "" : "url";
})
.on("click", function (d) {
if (!d.children) {
window.open("");
}
})
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.BaanNo;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.OrderId;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.ItNo;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.dateTime;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.gewicht;
});
d3.select(self.frameElement).style("height", height + "px");
};
I am new to d3.
I am having a problem with d3.js with the cluster. It gives me the following error:
Error: Invalid value for attribute transform="translate(undefined,undefined)"
And I have no idea why this gives it to me.
Code:
var loadd3 = function () {
function elbow(d, i) {
return "M" + (d.source.y + 100) + "," + d.source.x + "V" + d.target.x + "H" + (d.target.y + 100);
}
var width = (window.innerWidth - 100),
height = (window.innerHeight - 20);
var cluster = d3.layout.cluster()
.size([height, width - 160]);
var diagonal = d3.svg.diagonal()
.projection(function (d) {
return [d.y, d.x];
});
d3.select("svg").remove();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(40,0)");
var root = dataSource;
var nodes = cluster.nodes(root),
links = cluster.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function (d) {
return "translate(" + d.y + "," + d.x + ")";
})
node.append("rect")
.attr("width", 120)
.attr("height", 60)
.attr("y", -30)
.attr("rx", 5)
.attr("ry", 5);
node.append("rect")
.attr("class", "header")
.attr("width", 120)
.attr("height", 10)
.attr("y", -30)
.attr("rx", 5)
.attr("ry", 5);
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", -6)
.attr("class", function (d) {
return d.children ? "" : "url";
})
.on("click", function (d) {
if (!d.children) {
window.open("http://google.");
}
})
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.BaanNo;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.OrderId;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.ItNo;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.dateTime;
});
node.append("text")
.attr("x", function (d) {
return d.children ? 60 : 15
})
.attr("dy", 12)
.style("text-anchor", function (d) {
return d.children ? "end" : "start";
})
.text(function (d) {
return d.gewicht;
});
d3.select(self.frameElement).style("height", height + "px");
};
I am new to d3.
Share Improve this question edited Oct 21, 2017 at 0:26 ROMANIA_engineer 56.7k30 gold badges209 silver badges205 bronze badges asked Sep 1, 2015 at 8:59 FullyHumanProgrammerFullyHumanProgrammer 1011 gold badge3 silver badges19 bronze badges 5- the error is thrown from the line var node = ... .attr("transform", function (d)... I don't see your datasource. You wil solve it yourself if you console lig d.y and d.x in your function. – ee2Dev Commented Sep 1, 2015 at 10:31
-
Seems like the not every object in
nodes
array have x and y properties. Verify it using console.console.log(nodes);
– Gilsha Commented Sep 1, 2015 at 11:29 - @Gilsha That was indeed the problem, I logged everything, corrected my mistakes and it works prefectly now, thanks for your help :) – FullyHumanProgrammer Commented Sep 1, 2015 at 13:08
- @ee2Dev dataSource was being filled by an xmlHttpRequest, which I forgot to include in the code block above. Sorry 'bout that – FullyHumanProgrammer Commented Sep 1, 2015 at 13:09
- @Gilsha if you would leave an answer, I can accept it so that other users (Who for instance forget to check the ments) might find an answer here too. – FullyHumanProgrammer Commented Sep 1, 2015 at 13:33
1 Answer
Reset to default 7The reason for this error is, d.x
and d.y
properties are undefined
at sometimes.
Seems like not every object in nodes
array have x
and y
properties. Verify it by console logging nodes
array.
本文标签:
版权声明:本文标题:javascript - Error: Invalid value for <g> attribute transform="translate(undefined,undefined)" - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741217700a2360368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论