A simple bar chart with d3.js
Last active
August 25, 2015 20:01
-
-
Save robert-moore/b3bc08492540e6042247 to your computer and use it in GitHub Desktop.
Simple D3.js Bar Chart
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> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Updatable Charts (1 of 4)</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
body { | |
padding: 20px 0 0 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
var milesRun = [2, 5, 4, 1, 2, 6, 5]; | |
d3.select('body').append('svg') | |
.attr('height', 300) | |
.attr('width', 800) | |
.selectAll('rect') | |
.data(milesRun) | |
.enter() | |
.append('rect') | |
.attr('y', function (d, i) { return i * 40 }) | |
.attr('height', 35) | |
.attr('x', 0) | |
.attr('width', function (d) { return d*100}) | |
.style('fill', 'steelblue'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment