In d3Js, How would one draw basic line segments from a tsv file? Say the file declare, in one row of data, x1,y1,x2,y2. I want to draw two line segments as in the data below:
x0 y0 x1 y1 weight
0.5 0.5 0.2 0.2 2
0.25 0.35 0.7 0.8 1
I'm having trouble with the d3.tsv function here. I'm confident that the code below is fundamentally wrong, but just to show what I'm trying to do...
d3.tsv("data/sampledata.tsv", function(error, data) {
data.forEach(function(d) {
d.x0 = +d.x0;
d.y0 = +d.y0;
d.x1 = +d.x1;
d.y1 = +d.y1;
});
var line = svgContainer.append("line")
.attr("x1", function(d) { return (d.x0); })
.attr("y1", function(d) { return (d.y0); })
.attr("x2", function(d) { return (d.x1); })
.attr("y2", function(d) { return (d.y1); })
.attr("stroke-width", 2)
.attr("stroke", "black");
});
Could someone please point me in the right direction? The documentation out there refers mostly to creating paths through a series of data while I'm trying to produce individual line segments. Thanks in advance for any help.