Skip to content

Instantly share code, notes, and snippets.

@abhishekpolavarapu
Forked from weiglemc/README.md
Last active January 27, 2016 01:24
Show Gist options
  • Save abhishekpolavarapu/337680374993cf1d8c08 to your computer and use it in GitHub Desktop.
Save abhishekpolavarapu/337680374993cf1d8c08 to your computer and use it in GitHub Desktop.
D3 test.!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style type="text/css">
div.bar{
display: inline-block;
width: 20px;
height: 75px;
margin-right: 2px;
background-color: teal;"></div>
}
</style>
</head>
<body>
<script type="text/javascript">
var dataset = []; //Initialize empty array
for (var i = 0; i < 25; i++) { //Loop 25 times
var newNumber = Math.round(Math.random() * 30); //New random integer (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";
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment