Skip to content

Instantly share code, notes, and snippets.

@phoebebright
Created July 12, 2012 09:01
Show Gist options
  • Save phoebebright/3096857 to your computer and use it in GitHub Desktop.
Save phoebebright/3096857 to your computer and use it in GitHub Desktop.
d3 nested nest from csv data
<html>
<head>
<title>D3 Nested Nest Example</title>
<script src="http://d3js.org/d3.v2.js"></script>
</head>
<body>
<script>
d3.csv("./nest2.csv", function(csv_data){
var nested_data = d3.nest()
.key(function(d) { return d.region; })
.key(function(d) { return d.country; })
.entries(csv_data);
console.debug(nested_data);
alert(JSON.stringify(nested_data));
});
</script>
</body>
</html>
id region country us_country_code iso2_code main_trade-group imports_to exports_from total_trade group trade_balance year
1 Africa Algeria 7210 DZ OPEC 15455.9 1101.9 16557.8 high -14354 2006
2 Africa Algeria 7210 DZ OPEC 17816.1 1652.4 19468.5 high -16163.6 2007
3 Africa Germany 7210 DZ OPEC 17816.1 1652.4 19468.5 high -16163.6 2007
4 German Algeria 7210 DZ OPEC 15455.9 1101.9 16557.8 high -14354 2006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment