-
Notifications
You must be signed in to change notification settings - Fork 42
/
08_circles.html
91 lines (86 loc) · 1.39 KB
/
08_circles.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Array of objects, drawing circles</title>
<script type="text/javascript" src="d3.v3.js"></script>
<style type="text/css">
/* No style rules here yet */
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 500;
var h = 100;
var dataset = [
{
x: 5,
y: 20,
r: 10
},
{
x: 480,
y: 90,
r: 20
},
{
x: 250,
y: 50,
r: 15
},
{
x: 100,
y: 33,
r: 7
},
{
x: 330,
y: 95,
r: 18
},
{
x: 410,
y: 12,
r: 19
},
{
x: 475,
y: 44,
r: 25
},
{
x: 25,
y: 67,
r: 12
},
{
x: 85,
y: 21,
r: 5
},
{
x: 220,
y: 88,
r: 3
}
];
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d, i) {
return 40 + i * 40;
})
.attr("cy", h / 2)
.attr("r", function(d) {
return d.r;
});
</script>
</body>
</html>