D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Rainboylvx
Full window
Github gist
simple tree
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var g = svg.append("g").attr("transform", function(d) { return "translate(" + 00 + "," + 100 + ")"; }) var tree = d3.tree().size([300,300]) .separation(function(a,b){ return 1; }) var stratify = d3.stratify().parentId(function(d){ return d.parent }) d3.csv("data.csv", function(error, data) { //console.log(data) var root = stratify(data); var nodes = tree(root) var link = g.selectAll(".link") .data(root.links()) .enter().append("path") .attr("fill","none") .attr("stroke","black") .attr("class", "link") .attr("d", d3.linkVertical() .x(function(d) { return d.x; }) .y(function(d) { return d.y; })); var node = g.selectAll(".node") .data(root.descendants()) .enter() .append("g") .attr("class",".node") .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) node.append("circle") .attr("r",10) .attr("fill","#fff") .attr("stroke","black") }) </script> </body>
https://d3js.org/d3.v4.min.js