Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Created February 17, 2014 03:38
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 aaizemberg/9044309 to your computer and use it in GitHub Desktop.
Save aaizemberg/9044309 to your computer and use it in GitHub Desktop.
data matrix --> "html table" using d3.js
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<title>tablas desde d3.js</title>
<style>
table,td{border:1px solid green;border-collapse: collapse;}
td{padding: 8px;}
</style>
</head>
<body>
<script>
var matrix = [
[1, 2, 2, 4],
[5, 5, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
];
var tr = d3.select("body").append("table").selectAll("tr")
.data(matrix)
.enter().append("tr");
var td = tr.selectAll("td")
.data(function(d) { return d; })
.enter().append("td")
.text(function(d) { return d; });
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment