Last active
April 8, 2017 18:54
-
-
Save flunky/0cf80ff3dd4d66878151347b82378a2a to your computer and use it in GitHub Desktop.
D3 SVG Bar Chart Joining One Rect Per Datum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<style> .chart rect { fill: steelblue } </style> | |
<html><body> | |
<p>Here are the magic numbers from Lost: <span id="data"></span></p> | |
<svg class="chart" width="120" height="500"> | |
<rect></rect> | |
<rect></rect> | |
<rect></rect> | |
<rect></rect> | |
<rect></rect> | |
<rect></rect> | |
</svg> | |
<script> | |
var data = [4,8,15,16,23,42]; | |
document.getElementById("data").innerHTML = data; | |
d3.selectAll("rect") | |
.data(data) | |
.attr("width",19) | |
.attr("height",function(d) { return 10*d; }) | |
.attr("x",function(d,i) { return 20*i; }) | |
.attr("y",function(d) { return 420 - 10*d; }); | |
</script> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment