D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jadiehm
Full window
Github gist
Fade in scatterplot
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Facebook Data Requests by Country</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> h1 { font-family: sans-serif; font-size: 1.5em; margin-bottom:0; } p { font-family: sans-serif; font-size: .75em; color:gray; margin-bottom:0; } svg { background-color: white; } circle:hover { fill: #00664C; opacity: 1; } .axis path, .axis line { fill: none; stroke: black; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 11px; } </style> </head> <body> <h1>Facebook User Data</h1> <p>Number of requests for data by government officials vs. the percentage of those requests filled (July 2014 – Dec. 2014) | Source: <a href="https://govtrequests.facebook.com/">Facebook</a></p> <script type="text/javascript"> var w = 750; //sets the width variable var h = 400; //sets the height variable var padding = [25, 10, 40, 40]; //top, right, bottom, left var xScale = d3.scale.linear() //.domain([0,15000]) input values .range([padding[3], w - padding[1]]); //pixel values var yScale = d3.scale.linear() //.domain([0,15000]) input values .range([padding[0], h - padding[2]]); //pixel values var xAxis = d3.svg.axis() .scale(xScale) .orient("bottom") .ticks(14); 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("FBGovernmentRequests.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.dataRequests, +b.dataRequests); }); xScale.domain([0, d3.max(data, function(d){ return +d.dataRequests; }) ]); yScale.domain([ d3.max(data, function(d){ return +d.dataProduced; }), 0 ]); var circles = svg.selectAll("circle") .data(data) .enter() .append("circle"); circles.attr("cx", function(d){ return xScale(d.dataRequests); }) .attr("cy", function(d){ return yScale(d.dataProduced); }) .attr("r", 0.1) .attr("opacity", .4) .attr("fill", "#00CC99") .append("title") .text(function(d) { return d.Country + " requested data from " + d.dataRequests + " users and received " + d.dataProduced + " percent of those requests."; }); circles.sort(function(a, b){ return d3.ascending(+a.dataRequests, +b.dataProduced); }) .transition() //values after transition .delay(function(d, i){ return i * 20; }) .duration(1000) .attr("r", 4.5); 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.js
to a secure url
https://d3js.org/d3.v3.js