Created
March 2, 2014 19:58
-
-
Save ABrouwer/9312864 to your computer and use it in GitHub Desktop.
Assignment 4
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 dataset = []; | |
| d3.json("https://negativepostdata.firebaseio.com/#", | |
| function(d) | |
| {return dataset = d;}); | |
| JSON.parse(dataset) | |
| var w = 500; | |
| var h = 200; | |
| var barPadding = 1; | |
| //Creating an SVG element | |
| var svg = d3.select("body") | |
| .append("svg") | |
| .attr("width", w) | |
| .attr("height", h); | |
| svg.selectAll("rect") | |
| .data(dataset) | |
| .enter() | |
| .append("rect") | |
| .attr("x", 0) | |
| .attr("y", 0) | |
| .attr("width", 20) | |
| .attr("height", 100) | |
| .attr("x", function(d,i) { | |
| return i * (w / dataset.length); | |
| }) | |
| .attr ("y", function (d){ | |
| return h - (d * 4); | |
| }) | |
| .attr ("width", w / dataset.length - barPadding) | |
| .attr ("height", function(d) { | |
| return d * 4; | |
| }) | |
| .attr ("fill", function(d) { | |
| return "rgb(20, 240, " + (d * 10) + ")"; | |
| }); | |
| svg.selectAll("text") | |
| .data(dataset) | |
| .enter() | |
| .append("text") | |
| .text(function(d){ | |
| return d; | |
| }) | |
| .attr("x", function(d, i) { | |
| return i * (w /dataset.length) + 5; | |
| }) | |
| .attr("y", function(d) { | |
| return h - (d * 4) + 15; | |
| }) | |
| .attr("font-family", "sans-serif") | |
| .attr("font-size", "11px") | |
| .attr("fill", "white"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment