-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
352 lines (306 loc) · 12 KB
/
index.html
File metadata and controls
352 lines (306 loc) · 12 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="./lib/d3.v4.3.0.js"></script>
<script src="./dist/dimple.v2.3.0.js"></script>
<style>
h1 {
text-align: center;
text-shadow: 5px 5px 5px #7fffd4;
color: rgb(30,144,255);
}
h2 {
width:600px;
font-size:8px;
margin-left: auto;
margin-right: auto;
text-align: center;
color:rgb(186,85,211);
background-color:rgb(220,220,220);
}
div.years_buttons {
background-color: rgb(30,144,255);
background-size:8px 6px;
text-align: center;
padding: 3px;
margin: 7px;
}
h3 {
color: rgb(30,144,255);
font-size:25px;
}
.button{
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 10px 16px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
h4 {
color: rgb(30,144,255);
font-size:18px;
}
h5 {
color: rgb(255,20,147);
font-size:20px;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #008CBA;
}
.button1:hover {
background-color: #008CBA;
color: white;
}
</style>
</head>
<body>
<script type="text/javascript">
var body = d3.select("body")
.append("div")
.attr("style", "text-align:center");
body.append("h1").text("“泰坦尼克”逃生真相:妇女儿童优先只是个传说?");
body.append("h2").text("“泰坦尼克号”电影中,展示了人性的多样性。让人遗憾的是,“妇女儿童优先”的动人救生口号并非完全属实,获得优先权的主要是头等舱。统计数据表明,头等舱男乘客的生还率比三等舱中儿童的生还率还稍高一点与三等舱中的妇女生还率一致。")
var first = body.append("div")
.append("button")
.text("不同人群整体生还几率对比")
//.attr("type", "button")
.attr("class", "button button1");
first.on("click", function(){
d3.selectAll("body div svg").remove();
d3.selectAll("body div h3").remove();
d3.selectAll("body div h4").remove();
d3.selectAll("body div h5").remove();
var title = d3.select("body div")
.append("h3")
.text("不同人群的生还几率对比图");
var svg = dimple.newSvg("body div", 700, 500);
d3.csv("titanic_clean7.csv", function (data) {
var myChart = new dimple.chart(svg, data);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", "Level");
x.addOrderRule(["children", "women", "men", "old people"]);
var y = myChart.addPctAxis("y", "Number");
var s = myChart.addSeries("Survived", dimple.plot.bar);
s.afterDraw = function (shape, data) {
var s = d3.select(shape),
rect = {
x: parseFloat(s.attr("x")),
y: parseFloat(s.attr("y")),
width: parseFloat(s.attr("width")),
height: parseFloat(s.attr("height"))
};
// Only label bars where the text can fit
if (rect.height >= 8) {
// Add a text label for the value
svg.append("text")
.attr("x", rect.x + rect.width / 2)
.attr("y", rect.y + rect.height / 2 + 3.5)
.style("text-anchor", "middle")
.style("font-size", "10px")
.style("font-family", "sans-serif")
.style("opacity", 0.6)
.style("pointer-events", "none")
.text(d3.format(",d")(data.yValue) + "人");
}
};
myChart.addLegend(60, 10, 510, 20, "right");
myChart.draw();
});
d3.select("div").append("h4").text("从整体上来看,妇女和儿童的生还几率的确远大于男人");
})
var second = body.append("div")
.append("button")
.text("不同船舱等级的生还率总体对比")
.attr("class", "button button1")
.attr("type", "button");
second.on("click", function(){
d3.selectAll("body div h3").remove();
d3.selectAll("body div svg").remove();
d3.selectAll("body div h4").remove();
d3.selectAll("body div h5").remove();
var title = d3.select("body div")
.append("h3")
.text("不同船舱等级的生还率总体对比");
var svg = dimple.newSvg("body div", 700, 500);
d3.csv("titanic_clean2.csv", function (data) {
var myChart = new dimple.chart(svg, data);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", "Pclass");
x.addOrderRule("Pclass", true);
var y = myChart.addPctAxis("y", "Number");
var s = myChart.addSeries("Survived", dimple.plot.bar);
s.afterDraw = function (shape, data) {
var s = d3.select(shape),
rect = {
x: parseFloat(s.attr("x")),
y: parseFloat(s.attr("y")),
width: parseFloat(s.attr("width")),
height: parseFloat(s.attr("height"))
};
// Only label bars where the text can fit
if (rect.height >= 8) {
// Add a text label for the value
svg.append("text")
.attr("x", rect.x + rect.width / 2)
.attr("y", rect.y + rect.height / 2 + 3.5)
.style("text-anchor", "middle")
.style("font-size", "10px")
.style("font-family", "sans-serif")
.style("opacity", 0.6)
.style("pointer-events", "none")
.text(d3.format(",d")(data.yValue) + "人");
}
};
myChart.addLegend(60, 10, 510, 20, "right");
myChart.draw();
});
d3.select("div").append("h4").text("从图像上来看,乘客的生还几率根据其船舱等级依次降低。");
})
var third = body.append("div")
.append("button")
.text("不同船舱等级以及不同人群的生还率对比")
.attr("class", "button button1")
.attr("type", "button");
third.on("click", function(){
d3.selectAll("body div h3").remove();
d3.selectAll("body div svg").remove();
d3.selectAll("body div h4").remove();
d3.selectAll("body div h5").remove();
var title = d3.select("body div")
.append("h3")
.text("不同船舱等级以及不同人群的生还率对比");
var svg = dimple.newSvg("body div", 700, 500);
d3.csv("titanic_clean2.csv", function (data) {
var myChart = new dimple.chart(svg, data);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", ["Pclass", "Level"]);
x.addOrderRule("Pclass", true);
myChart.addMeasureAxis("y", "Number");
myChart.addSeries("Survived", dimple.plot.bar);
myChart.addLegend(60, 10, 510, 20, "right");
myChart.draw();
});
d3.select("div").append("h4").text("从图像上来看,头等舱的不同人群生还几率相对于其他等级的船舱基本都要高。");
})
var fifth = body.append("div")
.append("button")
.text("头等舱的男人生存比跟三等舱的女人和儿童对比")
.attr("class", "button button1")
.attr("type", "button");
fifth.on("click", function(){
d3.selectAll("body div h3").remove();
d3.selectAll("body div svg").remove();
d3.selectAll("body div h4").remove();
d3.selectAll("body div h5").remove();
var title = d3.select("body div")
.append("h3")
.text("头等舱的男人生存比跟三等舱的女人和儿童对比");
var svg = dimple.newSvg("body div", 700, 500);
d3.csv("titanic_clean5.csv", function (data) {
var myChart = new dimple.chart(svg, data);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", ["Pclass", "Level"]);
x.addOrderRule("Pclass", true);
var y = myChart.addPctAxis("y", "Number");
var s = myChart.addSeries("Survived", dimple.plot.bar);
s.afterDraw = function (shape, data) {
var s = d3.select(shape),
rect = {
x: parseFloat(s.attr("x")),
y: parseFloat(s.attr("y")),
width: parseFloat(s.attr("width")),
height: parseFloat(s.attr("height"))
};
// Only label bars where the text can fit
if (rect.height >= 8) {
// Add a text label for the value
svg.append("text")
// Position in the centre of the shape (vertical position is
// manually set due to cross-browser problems with baseline)
.attr("x", rect.x + rect.width / 2)
.attr("y", rect.y + rect.height / 2 + 3.5)
// Centre align
.style("text-anchor", "middle")
.style("font-size", "10px")
.style("font-family", "sans-serif")
// Make it a little transparent to tone down the black
.style("opacity", 0.6)
// Prevent text cursor on hover and allow tooltips
.style("pointer-events", "none")
// Format the number
.text(d3.format(",d")(data.yValue) + "人");
}
};
myChart.addLegend(60, 10, 510, 20, "right");
myChart.draw();
});
d3.select("div").append("h4").text("从图像上来看,头等舱男乘客的生还率比三等舱中儿童的生还率还稍高一点与三等舱中的妇女生还率几乎一致。");
})
var fouth = body.append("div")
.append("button")
.text("头等舱的女人生存比跟三等舱的男人对比")
.attr("class", "button button1")
.attr("type", "button");
fouth.on("click", function(){
d3.selectAll("body div svg").remove();
d3.selectAll("body div h3").remove();
d3.selectAll("body div h4").remove();
d3.selectAll("body div h5").remove();
var title = d3.select("body div")
.append("h3")
.text("头等舱的女人生存比跟三等舱的男人对比");
var svg = dimple.newSvg("body div", 700, 500);
d3.csv("titanic_clean3.csv", function (data) {
var myChart = new dimple.chart(svg, data);
//myChart.setBounds(60, 30, 510, 305)
var x = myChart.addCategoryAxis("x", ["Pclass", "Level"]);
x.addOrderRule("Pclass", true);
var y = myChart.addPctAxis("y", "Number");
var s = myChart.addSeries("Survived", dimple.plot.bar);
s.afterDraw = function (shape, data) {
var s = d3.select(shape),
rect = {
x: parseFloat(s.attr("x")),
y: parseFloat(s.attr("y")),
width: parseFloat(s.attr("width")),
height: parseFloat(s.attr("height"))
};
// Only label bars where the text can fit
if (rect.height >= 8) {
// Add a text label for the value
svg.append("text")
// Position in the centre of the shape (vertical position is
// manually set due to cross-browser problems with baseline)
.attr("x", rect.x + rect.width / 2)
.attr("y", rect.y + rect.height / 2 + 3.5)
// Centre align
.style("text-anchor", "middle")
.style("font-size", "10px")
.style("font-family", "sans-serif")
// Make it a little transparent to tone down the black
.style("opacity", 0.6)
// Prevent text cursor on hover and allow tooltips
.style("pointer-events", "none")
// Format the number
.text(d3.format(",d")(data.yValue) + "人");
}
};
myChart.addLegend(60, 10, 510, 20, "right");
myChart.draw();
});
d3.select("div").append("h4").text("从图像上来看,可以看出两者巨大的悬殊,头等舱几乎所有的妇女都生还了,而三等舱只有14%的男人能够生还。");
d3.select("div").append("h5").text("从统计数据表明,在泰坦尼克号上执行口号这样表述可能更准确一些:‘头等舱和二等舱的妇女和儿童优先’。");
})
</script>
</body>
</html>