Skip to content

Instantly share code, notes, and snippets.

@bretdavidson
Created November 14, 2016 19:47
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 bretdavidson/d378021613877f2d914795cbf943fec8 to your computer and use it in GitHub Desktop.
Save bretdavidson/d378021613877f2d914795cbf943fec8 to your computer and use it in GitHub Desktop.
var ann,
bar,
chart,
g,
gBar,
gEnter,
gRule,
line,
rects,
rule,
svg,
svgSelect,
text,
wrapper,
x,
debug;
debug = true;
// Define scales
x = d3.scaleLinear()
.domain([0, d3.max(data.map(function (d) { return +d.count; }))])
.range([0, 285]);
// Select svg container and join data
wrapper = d3.select(this).selectAll('svg').data([data]);
// Set height (change to dynamic)
height = 600;
svg = wrapper.enter().append('svg')
.classed('chart', true)
svgSelect = d3.select('.chart')
.attr('width', width)
.attr('height', height)
// Data Join
rects = svgSelect.selectAll("rect")
.data(data)
// Enter and Update
rects.enter().append("rect")
.attr("transform", function(d, i) { return "translate(0," + i * 25 + ")"; })
.attr("height", 25 - 1)
.merge(rects)
.attr("width", function(d) { return x(+d.count); })
// Exit
rects.exit().remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment