Last active
August 29, 2015 14:03
-
-
Save fieldoffice/e3682bf807d2c3f8bf7f to your computer and use it in GitHub Desktop.
Generate random numbers for d3 barchart
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 = []; | |
for (var i = 0; i < 25; i++) { //Loop 25 times | |
var newNumber = Math.round(Math.random() * 30); //New random number (0-30) | |
dataset = dataset.concat(newNumber); //Add new number to array | |
} | |
d3.select("body").selectAll("div") | |
.data(dataset) | |
.enter() | |
.append("div") | |
.attr("class", "bar") | |
.style("height", function(d) { | |
var barHeight = d * 5; | |
return barHeight + "px"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment