D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
raulisa
Full window
Github gist
Scatterplot PSE Data
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Assignment 5</title> <script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script> <style type="text/css"> body { background-color: #E0E4CC; font-family: 'Franklin Gothic Medium', 'Franklin Gothic', 'ITC Franklin Gothic', Arial, sans-serif; } h1 { font-size: 24px; margin: 0; color: gray; } p { font-size: 13px; margin: 10px 0 0 0; color: gray; } a { font-size: 13px; margin: 10px 0 0 0; color: #F38630; } svg { background-color: #E0E4CC; } circle:hover { fill: #F38630; } .axis path, .axis line { fill: none; stroke: gray; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 9px; } </style> </head> <body> <h1>US College Completion</h1> <p>Share of students at 4-year, public university who graduated within 6 years vs. share who never enrolled, by state (Fall 2008 Cohort). Source: <a href="https://nscresearchcenter.org/">National Student Clearinghouse</a></p> <script type="text/javascript"> var w = 500; var h = 400; var padding = [ 5, 10, 20, 30 ]; //Top, right, bottom, left var xScale = d3.scale.linear() .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") .tickFormat(function(d) { return d + "%"; }); var yAxis = d3.svg.axis() .scale(yScale) .orient("left") .tickFormat(function(d) { return d + "%"; }); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("fourYrPubPSECompRate_in6years.csv", function(data) { xScale.domain([ (d3.min(data, function(d) { return +d.completionRate; })-3), (d3.max(data, function(d) { return +d.completionRate; })+3) ]); yScale.domain([ (d3.max(data, function(d) { return +d.notEnrolled; })+3), 10 ]); var circles = svg.selectAll("circle") .data(data) .enter() .append("circle"); circles.attr("cx", function(d) { return xScale(d.completionRate); }) .attr("cy", function(d) { return yScale(d.notEnrolled); }) .attr("r", 3) .attr("fill", function(d) { if (d.State == "Oregon ") {return "purple"} else {return "#69D2E7"}; }) .append("title") .text(function(d) { return "The public postsecondary 4-year program completion rate for " + d.State + " is " + d.completionRate + "% and non-enrollment rate is " + d.notEnrolled + "%"; }); /*circles.sort(function(a, b) { return d3.ascending(+a.completionRate, +b.completionRate); }) .transition() .delay(function(d, i) { return i * 50; }) .duration(4000);*/ 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] + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js