Skip to content

Instantly share code, notes, and snippets.

@Vintharas
Last active August 21, 2019 21:43
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 Vintharas/ad0f80342b5e9aed5a1eb7b06a67f69a to your computer and use it in GitHub Desktop.
Save Vintharas/ad0f80342b5e9aed5a1eb7b06a67f69a to your computer and use it in GitHub Desktop.
Simple example rect data bind
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
<svg width=900 height=900></svg>
</head>
<body>
<script>
var cookiesThisWeek = [10, 20, 10, 50, 1, 12, 2];
d3.select("svg")
.selectAll("rect")
.data(cookiesThisWeek)
.enter()
.append('rect')
.attr('x', (_, i) => i*10)
.attr('y', (d) => 100 - d)
.attr('width', 10)
.attr('height', (d) => d)
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment