D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
DDArmstrong
Full window
Github gist
Top Organizational Donors to US Campaigns, 2014 Election Cycle
<html> <head> <title>Top US Donors, 2014 Election Cycle</title> <script type="text/javascript" src="https://d3js.org/d3.v3.min.js"> </script> <style type="text/css"> body { background-color: ivory; font-family: sans-serif; } h1 { font-size: 22px; margin: 0; font-family: verdana; } p { font-size: 16px; margin: 10px 0 0 0; font-family: arial; } svg { background-color: ivory; } rect:hover { fill: cadetblue; } .axis path, .axis line { fill: none; stroke: cadetblue; shape-rendering: crispEdges; } .axis text { font-family: arial; font-size: 12px } .y.axis path, .x.axis line { opacity: 0; } </style> </head> <body> <h1> Top Organizational Donors to US Federal Elections - 2014 </h1> <p>Source: https://www.opensecrets.org/orgs/list.php?cycle=2014</p> <script type="text/javascript"> var w = 1000; var h = 2000; var padding = [20, 10, 50, 250]; //top, right, bottom, left var widthScale = d3.scale.linear() .range([ 0, w - padding[1] - padding[3] ]); var heightScale = d3.scale.ordinal() .rangeRoundBands([ padding[0], h - padding[2] ], 0.3); var xAxis = d3.svg.axis() .scale(widthScale) .orient("bottom"); var yAxis = d3.svg.axis() .scale(heightScale) .orient("left"); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("TopDonors.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.Total_Contributions, +b.Total_Contributions); }); widthScale.domain([ 0, d3.max(data, function(d){ return +d.Total_Contributions; }) ]); heightScale.domain(data.map(function(d) { return d.Organization; } )); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", padding[3]) .attr("y", function(d) { return heightScale(d.Organization); }) .attr("width", function(d) { return widthScale(d.Total_Contributions); }) .attr("height", heightScale.rangeBand()) .attr("fill", "brown") .append("title") .text(function(d) { return d.Organization + " contributed $" + d.Total_Contributions / 1000000 + " million in 2014."; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(" + padding[3] + "," + (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.min.js
to a secure url
https://d3js.org/d3.v3.min.js