forked from scotthmurray/scattered-scatterplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_circles.html
More file actions
executable file
·122 lines (118 loc) · 2.15 KB
/
06_circles.html
File metadata and controls
executable file
·122 lines (118 loc) · 2.15 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>D3: Data-driven circles</title>
<script type="text/javascript" src="d3.js"></script>
<style type="text/css">
body {
background-color: gray;
}
svg {
background-color: white;
}
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 500;
var h = 100;
colors = [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#d62728",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf",
];
var dataset = [
{
x: 5,
y: 20,
r: 10,
fill: colors[0],
},
{
x: 480,
y: 90,
r: 20,
fill: colors[1],
},
{
x: 250,
y: 50,
r: 15,
fill: colors[2],
},
{
x: 100,
y: 33,
r: 7,
fill: colors[3],
},
{
x: 330,
y: 95,
r: 18,
fill: colors[4],
},
{
x: 410,
y: 12,
r: 19,
fill: colors[5],
},
{
x: 475,
y: 44,
r: 25,
fill: colors[6],
},
{
x: 25,
y: 67,
r: 12,
fill: colors[7],
},
{
x: 85,
y: 21,
r: 5,
fill: colors[8],
},
{
x: 220,
y: 88,
r: 3,
fill: colors[9],
},
];
//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) {
return d.x;
})
.attr("cy", function (d) {
return d.y;
})
.attr("r", function (d) {
return d.r;
})
.attr("fill", (d) => d.fill);
</script>
</body>
</html>