xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cambridge Development since 2010</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: #ddddff;
}
svg {
background-color: #ddddff;
}
</style>
</head>
<body>
<h2>Gross floor area of Cambridge development projects since 2010</h2>
<p>This chart shows the gross floor area, in square feet, of development projects in Cambridge, Mass since 2010.
It includes projects which are not yet completed. Mouse over a bar to see the project address and type.</p>
<script type="text/javascript">
var rowHeight = 12;
var height = 96 * rowHeight;
// Formatter for numbers with commas
format = d3.format('0,000');
var svg = d3.select("body")
.append("svg")
.attr("width", 700)
.attr("height", height);
d3.csv("https://gist.githubusercontent.com/kent37/313c30a0fda288f994a2/raw/0e489d6d0cbd877d4fec6d54b6ec9bc60839d4b4/CambridgeDevelopment.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a['Total.GFA'], +b['Total.GFA']);
//If your numeric values aren't sorting properly,
//try commenting out the line above, and instead using:
//
//return d3.descending(+a['Total.GFA'], +b['Total.GFA']);
//
//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.attr({
x: 0,
y: function(d, i) {
return i * rowHeight;
},
width: function(d) {
return d['Total.GFA'] / 1000;
},
height: rowHeight-2,
fill: function(d) {
return d['Year.Complete'] == 'Future' ? 'blue' : 'rgb(0, 0, 180)';
}
})
.append("title")
.text(function(d) {
return d['Address'] + " - " + d['Primary.Use'];
});
svg.selectAll("text")
.data(data)
.enter()
.append("text")
.text(function(d) {
return d['Year.Complete'] + " - " + format(+d['Total.GFA']) + ' sq ft';
})
.attr({
x: function(d) { return d['Total.GFA'] / 1000 + 20; },
y: function(d, i) {
return i * rowHeight + rowHeight/2 + 2;
},
'font-family': "sans-serif",
'font-size': "9px",
fill: "black"
})
.each(function(d) {
d.width = this.getBBox().width;
})
;
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js