Skip to content

Instantly share code, notes, and snippets.

@curran
Last active July 4, 2017 15:26
Show Gist options
  • Save curran/ea3bdf88768570280fe20b10134588a7 to your computer and use it in GitHub Desktop.
Save curran/ea3bdf88768570280fe20b10134588a7 to your computer and use it in GitHub Desktop.
[unlisted] Logo
license: mit
country population
China 1376048943
India 1311050527
USA 321773631
Indonesia 257563815
Brazil 207847528
<!DOCTYPE html>
<html>
<head>
<title>Rendering Rectangles</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<svg width="960" height="500"></svg>
<script>
const svg = d3.select("svg");
function render(data){
svg.selectAll("rect").data(data)
.enter().append("rect")
.attr("x", (d, i) => i * 30)
.attr("y", (d, i) => i * 30)
.attr("width", (d, i) => i * 30)
.attr("height", (d, i) => i * 30)
}
function type(d){
d.population = +d.population;
return d;
}
d3.csv("data.csv", type, render);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment