Name: Surbhi Shankar UIN: 01012632
Working through the examples from Scott Murray's tutorial at http://alignedleft.com/tutorials/d3/
Built with blockbuilder.org
Image and code from http://www.harding.edu/fmccown/r/
Embedding an image in Markdown:
Embedding R code in Markdown:
dataset <- c(25, 18, 14, 2, 10, 15, 20, 10, 12, 7, 5, 26, 11, 8, 5, 25, 14, 23, 19,
14, 11, 4, 7, 11, 23, 12, 7, 18, 10,
4, 8, 25, 9, 3)
barplot(dataset, col="red")
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Demo: Bar chart with random values</title>
<script type="text/javascript" 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; /* Gets overriden by D3-assigned height below */
margin-right: 2px;
background-color: teal;
}
</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>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js