I am trying to draw multiple lines that will create a map using coordinates that are in the json file located here.
https://www.dropbox.com/sh/luuzptywj2d7tv5/AAC23U5xWNzVL7mEPjPf5jPHa?dl=0
I am able to create the svg but I cannot get the lines to appear. Below is the code that I have used so far to create the svg and attempt to draw the lines. This is my first time using d3 and JSON files so any explanation is appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "UTF-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<title></title>
</head>
<body>
<script type = "text/javascript">
var streets; // declare global variable
var w = 960; // width of svg
var h = 800; // height of svg
var svg = d3.select( "body" )
.append( "svg" )
.attr( "width", w )
.attr( "height", h )
.style('background-color', 'black');
d3.json("/data/streets.json", function(json){
streets = json; //copy data from json to streets
console.log(json); // output json to console
var link = svg.selectAll(".link")
.data([streets])
.enter().append("line")
.attr("class", "link")
.style('stroke','green')
.style("stroke-width", 5);
link.attr("x1", function(d) { console.log(d); return d.x1; })
.attr("y1", function(d) { return d.y1; })
.attr("x2", function(d) { return d.x2; })
.attr("y2", function(d) { return d.y2; });
});
}
</script>
</body>
</html>