-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
57 lines (40 loc) · 1.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Test</title>
<script type="text/javascript" src="d3/d3.v3.js"></script>
<style type="text/css">
div.bar {
display: inline-block;
width: 20px;
height: 75px;
background-color: teal;
margin-right: 2px;
}
</style>
</head>
<body>
<script type="text/javascript">
var dataset = [ 25, 7, 5, 26, 11, 8, 25, 14, 23, 19,
14, 11, 22, 29, 11, 13, 12, 17, 18, 10,
24, 18, 25, 9, 3,25, 7, 5, 26, 11, 8,
25, 14, 23, 19,14, 11, 22, 29, 11, 13,
12, 17, 18, 10, 24, 18, 25, 9, 3];
var dataset = []; //Initialize empty array
for (var i = 0; i < 300; i++) { //Loop 25 times
var newNumber = Math.round(Math.random() * 30); //New random number (0-30)
dataset.push(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; //Scale up by factor of 5
return barHeight + "px";
});
</script>
</body>
</html>