Skip to content

Instantly share code, notes, and snippets.

@quizzicol
Created June 21, 2014 09:03
Show Gist options
  • Save quizzicol/e9185f9d88b5531ed1fb to your computer and use it in GitHub Desktop.
Save quizzicol/e9185f9d88b5531ed1fb to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="D3 intro 4 - bar chart" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var w = 200;
var h = 100;
var padding = 2;
var dataset = [5, 10, 15, 20, 25];
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", function(d, i) {
return i * (w / dataset.length);
})
.attr("y", function(d) {
return h - d*4;
})
.attr("width", w / dataset.length-padding)
.attr("height", function(d) {
return d*4;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment