-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_scatterplot.html
More file actions
68 lines (64 loc) · 1.82 KB
/
01_scatterplot.html
File metadata and controls
68 lines (64 loc) · 1.82 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scatterplot</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<div id="chart"></div>
<script type="text/javascript">
let w = 500;
let h = 100;
let dataset = [
[5, 20], [480, 90], [250, 50],
[100, 33], [330, 95], [410, 12],
[475, 44], [25, 67], [85, 21],
[220, 88] ];
// Crie o elemento svg
let svg = d3.select("#chart")
.append("svg")
.attr("width", w)
.attr("height", h);
let xScale = d3.scaleLinear()
.domain([0, d3.max(dataset, function(d) {
return d[0];
})])
.range([0,w]);
let yScale = d3.scaleLinear()
.domain([0, d3.max(dataset, function(d) {
return d[1];
})])
.range([h,0]);
// Depois adicione os elementos círculos
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d) {
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
.attr("r", 5);
// Depois adicione os labels
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.attr("x", function(d){
return xScale(d[0]);
})
.attr("y", function(d){
return yScale(d[1]);
})
.attr("font-family", "sansserif")
.attr("font-size", "11px")
.attr("fill", "red")
.text(function(d) {
return d[0] + ',' + d[1];
});
</script>
</body>
</html>