Built with blockbuilder.org
Created
February 17, 2018 00:56
-
-
Save robert-moore/bbaff6473fae658a2b84f931279ad273 to your computer and use it in GitHub Desktop.
SVG Bar Chart
This file contains hidden or 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
license: mit |
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
</head> | |
<body> | |
<!-- <svg width="500" height="500"> | |
<rect x="0" y="0" width="500" height="500" fill="lightcoral" /> | |
<circle cx="250" cy="250" r="250" fill="crimson" /> | |
</svg> --> | |
<script> | |
const milesRun = [3,2,5,8,3] | |
const svg = d3.select("body") | |
.append("svg") | |
.attr("height", 400) | |
.attr("width", 600) | |
const bars = svg.selectAll("rect") | |
.data(milesRun) | |
.enter() | |
.append("rect") | |
bars | |
.attr("x", 0) | |
.attr("y", (d, i) => i*40) | |
.attr("width", d => d*50) | |
.attr("height", 32) | |
.style("fill", "crimson") | |
bars | |
.append("title") | |
.text((d, i) => "You ran " + d + " miles on day " + (i + 1)) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment