-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (50 loc) · 1.42 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
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>D3 Test</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
div.bar {
display: inline-block;
width: 20px;
height: 75px;
margin-right: 1px;
background-color: teal;
}
</style>
</head>
<body>
<script>
var dataset = [ ];
var randomNum = i * ((5 * Math.random()) ^ 2);
for(var i = 0; i < randomNum.length; i++){
dataset.push( i * ((5 * Math.random()) ^ 2) );
}
var svgW = 500;
var svgH = 100;
d3.select("body").selectAll("div")
.data(dataset)
.enter()
.append("div")
.attr("class", "bar")
.style("height", function(d) {
var barHeightFactor = d * 5;
return barHeightFactor + "px";
});
var svg = d3.select("body")
.append("svg")
.attr("width", svgW)
.attr("height", svgH);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", function(d, i){
return i * (svgW / dataset.length);
})
.attr("y", 0)
.attr("width", 20)
.attr("height", 100)
</script>
</body>
</html>