Skip to content

Instantly share code, notes, and snippets.

@zbryikt
Created August 22, 2017 03:44
Show Gist options
  • Save zbryikt/062f411997560e84c4085ac6156344f7 to your computer and use it in GitHub Desktop.
Save zbryikt/062f411997560e84c4085ac6156344f7 to your computer and use it in GitHub Desktop.
D3js Tutorial - A working sample for http://blog.infographics.tw/2015/03/d3js-the-introduction/
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>
var death_rate = [['越南',24.26],['阿魯巴',17.48],['關島',10.01],['澳門',5.84]];
var div_data_bind = d3.select("body").selectAll("div").data(death_rate);
div_set = div_data_bind.enter().append("div");
div_data_bind.exit().remove();
div_set.text(function(d,i) {
return i + " / " + d[0];
});
div_set.style("height", "20px");
div_set.style("background", "red");
div_set.style("margin", "5px");
div_set.style("width", function(d,i) {
return (d[1] * 10)+"px";
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment