D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
clairepapu
Full window
Github gist
Bananas Consumption by Race
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Consumption of Bananas by Race</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; font-family: sans-serif; font-size: 11px; color: #ffd700;} svg { background-color: white; } h1{ font-size: 30px;} rect { fill: #ffd700;} rect:hover { opacity: 0.6;} </style> </head> <body> <h1>Bananas Consumption by Race</h1> <h2>Per Capita Retail Pounds Per Year</h2> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 400) .attr("height", 380); d3.csv("fruits-by-race-uploaded-to-gist-FINAL.csv", function(data) { data.sort(function(a, b) {return d3.descending(+a.Bananas, +b.Bananas);}); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", 210) .attr("y", function(d, i) {return i * 30;}) .attr("width", function(d) {return d.Bananas * 3;}) .attr("height", 25) .append("title") .text(function(d) {return d.RaceEthnicity + "'s annual consumption of BANANAS, in retail pounds, is " + d.Bananas;}); svg.selectAll("text") .data(data) .enter() .append("text") .text(function(d){return d.RaceEthnicity;}) .attr("x", 200) .attr("y", function(d, i){return i * 30 + 17;}) .attr({"fill": "#8b8970", "font-size": "12px", "text-anchor": "end"})}); </script> <p>Sources: Food Intakes Converted to Retail Commodities Databases (ARS) and<br /> Food Availability (Per Capita) Data System; <a href="https://www.ers.usda.gov/data-products/commodity-consumption-by-population-characteristics.aspx#27850">Table 1: Fruit Availablity;</a> United States<br /> Department of Agriculture, Economic Research Service, 1999-2002.</p> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js