Skip to content

Instantly share code, notes, and snippets.

@mbostock

mbostock/.block Secret

Last active May 22, 2019 12:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbostock/844752 to your computer and use it in GitHub Desktop.
Save mbostock/844752 to your computer and use it in GitHub Desktop.
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<table id="countries"></table>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
d3.json("sample.json", function(error, json) {
if (error) throw error;
var data = d3.nest()
.key(function(d) { return d.Country.toLowerCase(); })
.sortKeys(d3.ascending)
.map(json);
var tr = d3.select("#countries")
.selectAll("tr")
.data(d3.entries(data))
.enter().append("tr");
tr.append("th")
.text(function(d) { return d.key; });
tr.selectAll("td")
.data(function(d) { return d.value; })
.enter().append("td")
.text(function(d) { return d.Aspect + ": " + d.Value; });
});
</script>
[
{"Country": "France", "Aspect": "Cost_of_Living", "Value": 55},
{"Country": "France", "Aspect": "Leisure_&_Culture", "Value": 81},
{"Country": "France", "Aspect": "Economy", "Value": 69},
{"Country": "France", "Aspect": "Environment", "Value": 72},
{"Country": "France", "Aspect": "Freedom", "Value": 100},
{"Country": "France", "Aspect": "Health", "Value": 100},
{"Country": "France", "Aspect": "Infrastructure", "Value": 92},
{"Country": "France", "Aspect": "Risk_&_Safety", "Value": 100},
{"Country": "France", "Aspect": "Climate", "Value": 87},
{"Country": "France", "Aspect": "Final", "Value": 82},
{"Country": "Australia", "Aspect": "Cost_of_Living", "Value": 56},
{"Country": "Australia", "Aspect": "Leisure_&_Culture", "Value": 82},
{"Country": "Australia", "Aspect": "Economy", "Value": 71},
{"Country": "Australia", "Aspect": "Environment", "Value": 76},
{"Country": "Australia", "Aspect": "Freedom", "Value": 100},
{"Country": "Australia", "Aspect": "Health", "Value": 87},
{"Country": "Australia", "Aspect": "Infrastructure", "Value": 92},
{"Country": "Australia", "Aspect": "Risk_&_Safety", "Value": 100},
{"Country": "Australia", "Aspect": "Climate", "Value": 87},
{"Country": "Australia", "Aspect": "Final", "Value": 81},
{"Country": "Switzerland", "Aspect": "Cost_of_Living", "Value": 41},
{"Country": "Switzerland", "Aspect": "Leisure_&_Culture", "Value": 86},
{"Country": "Switzerland", "Aspect": "Economy", "Value": 79},
{"Country": "Switzerland", "Aspect": "Environment", "Value": 78},
{"Country": "Switzerland", "Aspect": "Freedom", "Value": 100},
{"Country": "Switzerland", "Aspect": "Health", "Value": 95},
{"Country": "Switzerland", "Aspect": "Infrastructure", "Value": 96},
{"Country": "Switzerland", "Aspect": "Risk_&_Safety", "Value": 100},
{"Country": "Switzerland", "Aspect": "Climate", "Value": 77},
{"Country": "Switzerland", "Aspect": "Final", "Value": 81}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment