-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch1-12.html
135 lines (112 loc) · 3.65 KB
/
ch1-12.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!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: 4px;
/*background-color: teal;*/
}
</style>
</head>
<body>
<div>
<p>
<svg width="250" height="250">
<!-- <rect x="25" y="0" width="500" height="50"></rect>
<circle cx="250" cy="250" r="25" fill="yellow" stroke="orange" stroke-width="5"/>
<ellipse cx="290" cy=290 rx="10" ry="25"/>
<line class='line1' x1="300" y1="300" x2="400" y2="400" stroke="black"/>
<line x1="0" y1="0" x2="500" y2="50" stroke="black"/>
<text x="250" y="50" font-family="sans-serif" font-size="25">Easy Peasy</text> -->
<!-- <circle cx="25" cy="25" r="20" fill="rgba(128, 0, 128, 1.0)"/>
<circle cx="50" cy="25" r="20" fill="rgba(0, 0, 255, 0.75)"/>
<circle cx="75" cy="25" r="20" fill="rgba(0, 255, 0, 0.5)"/>
<circle cx="100" cy="25" r="20" fill="rgba(255, 255, 0, 0.25)"/>
<circle cx="125" cy="25" r="20" fill="rgba(255, 0, 0, 0.1)"/> -->
<!-- <circle cx="25" cy="25" r="20"
fill="rgba(128, 0, 128, 0.75)"
stroke="rgba(0, 255, 0, 0.25)" stroke-width="10"/>
<circle cx="75" cy="25" r="20"
fill="rgba(0, 255, 0, 0.75)"
stroke="rgba(0, 0, 255, 0.25)" stroke-width="10"/>
<circle cx="125" cy="25" r="20"
fill="rgba(255, 255, 0, 0.75)"
stroke="rgba(255, 0, 0, 0.25)" stroke-width="10"/> -->
<!-- <circle cx="25" cy="25" r="20" fill="purple"
stroke="green" stroke-width="10"
opacity="0.9"/>
<circle cx="65" cy="25" r="20" fill="green"
stroke="blue" stroke-width="10"
opacity="0.5"/>
<circle cx="105" cy="25" r="20" fill="yellow"
stroke="red" stroke-width="10"
opacity="0.1"/> -->
<!-- <circle cx="25" cy="25" r="20"
fill="rgba(128, 0, 128, 0.75)"
stroke="rgba(0, 255, 0, 0.25)" stroke-width="10"/>
<circle cx="65" cy="25" r="20"
fill="rgba(128, 0, 128, 0.75)"
stroke="rgba(0, 255, 0, 0.25)" stroke-width="10"
opacity="0.5"/>
<circle cx="105" cy="25" r="20"
fill="rgba(128, 0, 128, 0.75)"
stroke="rgba(0, 255, 0, 0.25)" stroke-width="10"
opacity="0.2"/> -->
</svg>
</p>
</div>
<script type="text/javascript">
var w = 1500;
var h = 50;
var dataset = [];
//creates random data for bargraph
for(var i = 0; i < 50; i++){
dataset.push( Math.round((i + 2) * Math.random(2)));
}
//creates bargraph
// d3.select('body')
// .selectAll("p")
// .data(dataset)
// .enter()
// .append("div")
// //.text(function(d) {return d; })
// .style("background-color","teal")
// .style("height", function(d){
// var barHeightFactor = d * 5;
// return barHeightFactor + 'px';
// })
// .attr("class", "bar");
var svg = d3.select('body').append("svg");
svg.style("width", w)
.style("height", h);
var circles = svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle");
circles.attr("cx", function(d, i){
return (i * 50) + 25;
})
.attr("cy", h/2)
.attr("r", function(d){
return d;
})
.attr("fill", function(d){
return "rgba(" + (d*15) + ', ' + (d*13) + ', ' + (Math.round(Math.random() * 100)) + ', ' + Math.random() + ")";
})
.attr("stroke", "orange")
.attr("stroke-width", function(d) {
return d/2;
});
// .style("height", function(d){
// var barHeightFactor = d * 5;
// return barHeightFactor + 'px';
// })
// .attr("class", "bar");
</script>
</body>
</html>