-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatterplot.html
More file actions
46 lines (42 loc) · 1.26 KB
/
scatterplot.html
File metadata and controls
46 lines (42 loc) · 1.26 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<script>
var h = 350;
var w = 400;
monthlySales = [
{"month":10, "sales":100, "color": "blue"},
{"month":20, "sales":130, "color": "yellow"},
{"month":30, "sales":250, "color": "green"},
{"month":40, "sales":300, "color": "red"},
{"month":50, "sales":265, "color": "purple"},
{"month":60, "sales":225, "color": "grey"},
{"month":70, "sales":180, "color": "orange"},
{"month":80, "sales":120, "color": "black"},
{"month":90, "sales":145, "color": "teal"},
{"month":100, "sales":130, "color": "black"}
];
//create SVG
var svg = d3.select("body")
.append("svg")
.attr({ width:w, height: h});
//add dots
var dots = svg.selectAll("circle")
.data(monthlySales)
.enter()
.append("circle")
.attr({
"cx": function(d) {return d.month;},
"cy": function(d) {return h-d.sales;},
"r":10,
"fill": function(d) {return d.color;}
});
</script>
</body>
</html>