Skip to content

Instantly share code, notes, and snippets.

@curran
Last active November 2, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curran/d3f2271e133cd42ec2115cbd2e4520bd to your computer and use it in GitHub Desktop.
Save curran/d3f2271e133cd42ec2115cbd2e4520bd to your computer and use it in GitHub Desktop.
Hello D3 with Data
license: mit
<!DOCTYPE html>
<html>
<head>
<title>HTML Starter</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script>
var data = [
{ "name": "China", "population": 1379600000 },
{ "name": "India", "population": 1330780000 },
{ "name": "United States", "population": 324824000 },
{ "name": "Indonesia", "population": 260581000 },
{ "name": "Brazil", "population": 206879000 },
{ "name": "Pakistan", "population": 194680000 },
{ "name": "Nigeria", "population": 186987000 },
{ "name": "Bangladesh", "population": 161345000 },
{ "name": "Russia", "population": 146691020 },
{ "name": "Russia", "population": 146691020 },
{ "name": "Mexico", "population": 128632000 }
];
d3.select("body")
.selectAll("h1")
.data(data)
.enter().append("h1")
.text(function(d) { return d.name; });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment