D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
Abechtel
Full window
Github gist
Exercise 6
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Chicago Fed Loans to Individuals (in billions)</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; font-family: Helvetica; } svg { background-color: white; } circle:hover { fill: lightblue; } .axis path, .axis line { fill:none; stroke: black; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 11px; } </style> </head> <body> <h1>Relationship of Loans to Individuals and Net Interest Income (in billions)</h1> <p> This scatterplot shows the relationship between the Chicago Fed's Loans to Individuals and its Net Interest Income for a given year between 1966 and 2012; Source: <a href="https://fdic.gov">FDIC</a> <p>Loans to Individuals are plotted on the X axis; Net Interest Income is plotted on the Y axis</p> <script type="text/javascript"> var w = 800; var h = 400; var padding = [ 20, 50, 30, 50 ]; var dateFormat = d3.time.format("%Y"); var xScale = d3.time.scale() .range([ padding[3], w - padding[1] - padding[3] ]); var yScale = d3.scale.linear() .range([ padding[0], h - padding[2] ]); var xAxis = d3.svg.axis() .scale(xScale) .orient("bottom") .ticks (10) .tickFormat(function(d) { return dateFormat(d); }); var yAxis = d3.svg.axis() .scale(yScale) .orient("left"); var line = d3.svg.line() .x(function(d) { return xScale(dateFormat.parse(d.Year)); }) .y(function(d) { return yScale(d.individualloans); }); var interestline = d3.svg.line() .x(function(d) { return xScale(dateFormat.parse(d.Year)); }) .y(function(d) { return yScale(d.netinterestincome); }); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("ChicagoFDIC.csv", function(data) { xScale.domain([ d3.min(data, function(d) { return dateFormat.parse(d.Year); }), d3.max(data, function(d) { return dateFormat.parse(d.Year); }) ]); yScale.domain([ d3.max(data, function(d) { return +d.individualloans; }), 0 ]); svg.data([ data ]) .append("path") .attr("class", "Loans to Individuals") .attr("d", line) .attr("fill", "none") .attr("stroke", "darkblue") .attr("stroke-width", 2); svg.data([ data ]) .append("path") .attr("class", "Loans to Individuals") .attr("d", interestline) .attr("fill", "none") .attr("stroke", "red") .attr("stroke-width", 2); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + (h - padding[2]) + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + (padding[3] - 5) + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js