D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
johndhancock
Full window
Github gist
Running Backs with 420+ touches (Week 4)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Loading CSV Data with D3</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> </head> <body> <style type="text/css"> body { background-color: white; font-family: "Helvetica Neue", Arial, sans-serif; } h1 { font-size: 36px; margin: 0; } p { font-size: 14px; margin: 18px 0 0 0; } svg { background-color: white; } .axis path, .axis line { fill: none; stroke: #545454; shape-rendering: crispEdges; } .axis text { font-family: "Helvetica Neue", Arial, sans-serif; font-size: 10px; } .y.axis text { font-size: 8px; } .y.axis path, .y.axis line { opacity: 0; } </style> <h1>Runningbacks with 420 or more touches in a season</h1> <p>Sixteen running backs have had 420 or more touches in a single season since the NFL/AFL merger in 1970. For some, the 420-plus season was the beginning of the end for a career.</p> <script type="text/javascript"> var dimensions = { w: 600, h: 2000, padding: { t: 25, r: 25, b: 25, l: 125 } } var xScale = d3.scale.linear() .range([0, dimensions.w - dimensions.padding.r - dimensions.padding.l]); var yScale = d3.scale.ordinal() .rangeRoundBands([dimensions.padding.t, dimensions.h - dimensions.padding.b], .5); var xAxis = d3.svg.axis() .scale(xScale) .orient('bottom'); var yAxis = d3.svg.axis() .scale(yScale) .orient("left"); var svg = d3.select("body") .append("svg") .attr("width", dimensions.w) .attr("height", dimensions.h); //Load in contents of CSV file d3.csv("TouchesData.csv", function(data) { xScale.domain([0, d3.max(data, function(d) { return +d.YScm; }) ]); yScale.domain(data.map(function(d) { return d.Player; } )); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", dimensions.padding.l) .attr("y", function(d) { return yScale(d.Player); }) .attr("width", function(d) { return xScale(d.YScm); }) .attr("height", yScale.rangeBand()) .style("fill",function(d) { return d.Touches >= 420 ? "red" : "#545454 "; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(" + dimensions.padding.l + "," + (dimensions.h - dimensions.padding.b) +")") .call(xAxis); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + dimensions.padding.l + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js