Skip to content

Instantly share code, notes, and snippets.

@elsherbini
Created June 12, 2013 18:59
Show Gist options
  • Save elsherbini/5768111 to your computer and use it in GitHub Desktop.
Save elsherbini/5768111 to your computer and use it in GitHub Desktop.
SO barchart
{"description":"SO barchart","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
var data_votes = [5,7,8,9,3,11,7,2,12],
w = 420,
h = 112,
yoffset = 200,
barPadding = 5,
xoffset = 50,
scale = d3.scale.linear(),
svg = d3.select("svg");
scale.domain([0,d3.max(data_votes)])
scale.range([0,h]);
console.log(scale(12));
var bars = svg.selectAll("rect")
.data(data_votes)
.enter().append("rect")
.attr("x", function(d, i) {return i * (w / data_votes.length)+ xoffset;})
.attr("y", function(d){return h + yoffset - scale(d);})
.attr("width", w / data_votes.length - barPadding)
.attr("height", function(d) {return scale(d);})
.attr("fill", "teal");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment