forked from scotthmurray/scattered-scatterplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_data_values.html
More file actions
executable file
·71 lines (56 loc) · 1.37 KB
/
Copy path05_data_values.html
File metadata and controls
executable file
·71 lines (56 loc) · 1.37 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Using data values</title>
<script type="text/javascript" src="d3.v3.js"></script>
</head>
<body>
<script type="text/javascript">
//
// Using a simple array of numeric values
//
var numbers = [ 5, 10, 15, 20, 25 ];
var dataset = [ 5, 10 , 20, 15, 18 ];
var w = 500;
var h = 200;
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.select("svg").selectAll("circle")
.data(dataset)
.enter()
.append("circle");
// select all the circles
// set attribute to the datavalue
// so radius size is associated to
// data number
d3.selectAll("circle")
.attr("r", function(d){
return d;
});
d3.select("body").selectAll("h3")
.data(numbers)
.enter()
.append("h3")
.text(function(d) { return d; });
//
// Using an array of *objects*, each with multiple values
//
var animals = [
{ animal: "cat", type: "mammal" },
{ animal: "snake", type: "reptile" },
{ animal: "warbler", type: "bird" },
{ animal: "human", type: "mammal"}
];
d3.select("body").selectAll("p")
.data(animals)
.enter()
.append("p")
.text(function(d) {
return "A " + d.animal + " is a " + d.type;
});
</script>
</body>
</html>