Skip to content

Instantly share code, notes, and snippets.

@robert-moore
Last active August 25, 2015 20:01
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 robert-moore/b3bc08492540e6042247 to your computer and use it in GitHub Desktop.
Save robert-moore/b3bc08492540e6042247 to your computer and use it in GitHub Desktop.
Simple D3.js Bar Chart

A simple bar chart with d3.js

<!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