Created
November 14, 2016 19:47
-
-
Save bretdavidson/d378021613877f2d914795cbf943fec8 to your computer and use it in GitHub Desktop.
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
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