Last active
April 8, 2017 19:03
-
-
Save flunky/074d81036b8a72b4e4bf5eff77f5507a to your computer and use it in GitHub Desktop.
D3 SVG Bar Chart Creating 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"> | |
</svg> | |
<script> | |
var data = [4,8,15,16,23,42]; | |
document.getElementById("data").innerHTML = data; | |
d3.select(".chart") | |
.selectAll("rect") | |
.data(data) | |
.enter().append("rect") | |
.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