D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
patiencehaggin
Full window
Github gist
First try at Day 7 HW
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> var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) data = d3.json("nations.json", function(error, data) { if (error) return error; console.log(data[0].income) } ) // original data // scale for the years var xScale = d3.scaleLog() .domain(1800, 2010) .range([0,960]); // scale for the income var yScale = d3.scaleLinear() .domain([0, 100000]) .range([500,0]); var line = d3.line() .x(function(d) {return xScale(d[0])}) .y(function(d) {return yScale(d[1])}) console.log(line(data)); svg.append("path") .datum(data) //.datum tells the computer to create ONE thing, vs plotting multiple circles .attr("d", line); //The shape of an SVG Path element is defined by one attribute: d </script> </body>
https://d3js.org/d3.v4.min.js