Created
March 22, 2012 06:54
-
-
Save enjalot/2156737 to your computer and use it in GitHub Desktop.
samples for tributary
This file contains hidden or 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 w = 600 | |
| , h = 467 | |
| var data1 = [ | |
| 5, | |
| 20, | |
| 55, | |
| 60, | |
| 89 | |
| ]; | |
| function bars(data) | |
| { | |
| var max = d3.max(data) | |
| //nice breakdown of d3 scales | |
| //http://www.jeromecukier.net/blog/2011/08/11/d3-scales-and-color/ | |
| x = d3.scale.linear() | |
| .domain([0, max]) | |
| .range([0, w]) | |
| y = d3.scale.ordinal() | |
| .domain(d3.range(data.length)) | |
| .rangeBands([0, h], .2) | |
| var vis = d3.select("svg") | |
| //a good written tutorial of d3 selections coming from protovis | |
| //http://www.jeromecukier.net/blog/2011/08/09/d3-adding-stuff-and-oh-understanding-selections/ | |
| var bars = vis.selectAll("rect.bar") | |
| .data(data) | |
| //update | |
| bars | |
| .attr("fill", "#0a0") | |
| .attr("stroke", "#050") | |
| //enter | |
| bars.enter() | |
| .append("svg:rect") | |
| .attr("class", "bar") | |
| .attr("fill", "#800") | |
| .attr("stroke", "#800") | |
| //exit | |
| bars.exit() | |
| .remove() | |
| //apply to everything (enter and update) | |
| bars | |
| .attr("stroke-width", 4) | |
| .attr("width", x) | |
| .attr("height", y.rangeBand()) | |
| .attr("transform", function(d,i) { | |
| return "translate(" + [0, y(i)] + ")" | |
| }) | |
| } | |
| bars(data1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment