-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.html
102 lines (87 loc) · 3.31 KB
/
index.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
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="d3/d3.v3.js"></script>
<title>d3 Examples</title>
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-md-2">
<img src="resources/d3logo.png">
</div>
<div class="col-md-10">
<h1 class="logo">D3 Examples</h1>
<h4>Richard Dalton</h4>
<div class="btn-group btn-group-md" role="group" aria-label="...">
<a href="index.html" class="btn btn-default" role="button">Home</a>
<a href="svg.html" class="btn btn-default" role="button">SVG</a>
<a href="barChart.html" class="btn btn-default" role="button">Bar</a>
<a href="pieChart.html" class="btn btn-default" role="button">Pie</a>
<a href="bubbleChart.html" class="btn btn-default" role="button">Bubble</a>
<a href="force.html" class="btn btn-default" role="button">Force</a>
<a href="globe.html" class="btn btn-default" role="button">Globe</a>
<a href="https://d3js.org" class="btn btn-default" role="button">D3.js</a>
</div>
</div>
</div>
</div>
</header>
<div class="container">
<h3>Data Driven Documents</h3>
<p>D3 allows document elements to be generated from data. Hence the name Data Driven Documents (D3).</p>
<p>In the example below, and array of json key-value pairs are rendered as headings and paragraphs. We append a div
for each data item, and then within that div we render a heading for the key and a paragraph for the value.</p>
<div class="col-md-6">
<div id="draw_here"></div>
</div>
<div class="col-md-6">
<pre>
data = [
{"key": "First Heading", "value":"First Paragraph"},
{"key": "Second Heading", "value":"Second Paragraph"},
{"key": "Third Heading", "value":"Third Paragraph"},
{"key": "Fourth Heading", "value":"Fourth Paragraph"},
{"key": "Fifth Heading", "value":"Fifth Paragraph"},
];
//Create SVG element
var doc = d3.select("#draw_here");
var doc_item = doc.selectAll("div")
.data(data)
.enter()
.append("div");
doc_item.append("h4").text(function (d) {
return d.key;
});
doc_item.append("p").text(function (d) {
return d.value;
})
</pre>
</div>
</div>
<script>
data = [
{"key": "First Heading", "value":"First Paragraph"},
{"key": "Second Heading", "value":"Second Paragraph"},
{"key": "Third Heading", "value":"Third Paragraph"},
{"key": "Fourth Heading", "value":"Fourth Paragraph"},
{"key": "Fifth Heading", "value":"Fifth Paragraph"},
];
//Create SVG element
var doc = d3.select("#draw_here");
var doc_item = doc.selectAll("div")
.data(data)
.enter()
.append("div");
doc_item.append("h4").text(function (d) {
return d.key;
});
doc_item.append("p").text(function (d) {
return d.value;
})
</script>
</body>
</html>