Skip to content

Instantly share code, notes, and snippets.

@dongxiahe
Created September 7, 2015 17:05
Show Gist options
  • Select an option

  • Save dongxiahe/837d700ca758438261e0 to your computer and use it in GitHub Desktop.

Select an option

Save dongxiahe/837d700ca758438261e0 to your computer and use it in GitHub Desktop.
The Average Commercial Housing Price of China Since 2000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Creating SVG Elements from Data</title>
<script type="text/javascript" src="../../d3.v3.js"></script>
<style type="text/css">
body {
background-color: #dddddff;
}
svg {
background-color: while;
}
</style>
</head>
<body>
<p><h2>The National Commercial Housing Price of China Since 2000 (RMB/m2)</h2></p>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
.attr("width", 300)
.attr("height", 500);
d3.csv("thenationalcommercialhousingpriceofChinasince2000.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.commercialHousingAverageSellingPrice, +b.commercialHousingAverageSellingPrice);
});
var rect = svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
rect.attr("x", 0)
.attr("y", function(d, i){
return i * 15;
})
.attr("width", function(d) {
return d.commercialHousingAverageSellingPrice * 0.05
})
.attr("height", 8)
.append("title")
.text(function(d) {
return d.year+ "'s commercial housing average selling price is " + d.commercialHousingAverageSellingPrice;
});
});
</script>
</body>
</html>
We can make this file beautiful and searchable if this error is corrected: It looks like row 15 should actually have 3 columns, instead of 2 in line 14.
year,commercialHousingAverageSellingPrice,
2013,6237,
2012,5790,
2011,5357,
2010,5032,
2009,4681,
2008,3800,
2007,3863,
2006,3366,
2005,3167,
2004,2778,
2003,2359,
2002,2250,
2001,2170,
2000,2112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment