D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
1pixelzz
Full window
Github gist
City Park Data
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>City Park Acreage</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: #6CA698; } svg { background-color: white; } h2 { font-size: "36"; font-weight: "bold"; font-family: "Helvetica"; color: #ffffff; } </style> </head> <body> <h2> City Park Total Acreage</h2> <script type="text/javascript"> var svg = d3.select("body") .append("svg") .attr("width", 1920) .attr("height", 2200); d3.csv("Map_Parks.csv", function(data) { data.sort(function(a, b) { //return d3.descending(a.acreage, b.acreage); //If your numeric values aren't sorting properly, //try commenting out the line above, and instead using: // return d3.descending(+a.acreage, +b.acreage); // //Data coming in from the CSV is saved as strings (text), //so the + signs here force JavaScript to treat those //strings instead as numeric values, thereby fixing the //sort order (hopefully!). }); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.style("fill", "#868C35"); rects.attr("x", 300) .attr("y", function(d, i) { return i * 25; }) .attr("width", function(d) { return d.acreage * 2; }) .attr("height", 20) .append("title") .text(function(d) { return d.name + "'s total acreage is " + d.acreage; }); // add axis labels on left, 10px apart, starting at 8px down and 190px across svg.selectAll("text") .data(data) .enter() .append("text") .text(function(d){ return d.name; }) .attr("x", 280) .attr("y", function(d, i){ return i * 25 + 15; }) // set the type attributes for the labels .attr({ "fill": "black", "font-family": "sans-serif", "font-size": "14px", "text-anchor": "end" }) }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js