Built with blockbuilder.org
xxxxxxxxxx
<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; }
path{
stroke: black;
stroke-width: 5;
}
</style>
</head>
<body>
<script>
var margin = { top: 20, right: 20, bottom: 20, left: 20 };
var width = 960 - margin.left - margin.right;
var height = 500 - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
data = d3.json("nations.json", function(error, data) {
data = data[0].income
if (error) return error;
var xScale = d3.scaleLinear()
.domain([1800, 2010])
.range([0, width]); //chart becomes flipped if enter [960, 0] into range instead
var yScale = d3.scaleLinear()
.domain([0, 100000])
.range([height,0]);
// axes
var x = d3.axisBottom()
.scale(xScale)
.ticks(10, ".0f");
var y = d3.axisLeft()
.scale(yScale);
// axes
var xAxis = svg.append("g")
.call(x)
.attr("transform", "translate(0, " + height + ")");
var yAxis = svg.append("g")
.call(y);
// var yLabel = yAxis.append("text")
// .text("income per capita, inflation adjusted (dollars)")
// .attr("class", "axis")
// .attr("transform", "translate(" + (margin.left * 0.85) + ", 0) rotate(-90)")
// .attr("text-anchor", "end");
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