forked from SociallyCompute/MizzouSENG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
58 lines (51 loc) · 1.81 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
<!DOCTYPE html>
<html>
<head>
<title>Presidential Primary Data 2016</title>
<link href="app.css" rel="stylesheet" type="text/css">
<script src="jquery-1.12.0.min.js"></script>
<script src="d3.v3.min.js"></script>
</head>
<body>
<h2>Democratic Primary Polls</h2>
<div id="graph2"></div>
<h2>GOP Primary Polls</h2>
<div id="graph"></div>
<script>
var url = "http://elections.huffingtonpost.com/pollster/api/charts/2016-national-gop-primary";
var url2 = "http://elections.huffingtonpost.com/pollster/api/charts/2016-national-democratic-primary";
$.ajax(url, {
dataType: "jsonp",
jsonpCallback: "pollsterCallback",
cache: true,
success: function(data) {
makeGraph("#graph", data);
}
});
$.ajax(url2, {
dataType: "jsonp",
jsonpCallback: "pollsterPoll",
cache: true,
success: function(data) {
makeGraph("#graph2", data);
}
});
function makeGraph(id, data) {
var candidateBar = d3.select(id).selectAll("div").data(data.estimates);
var candidateWrapper = candidateBar.enter().append("div").classed("group", true);
candidateWrapper.append("div")
.classed("choice", true)
.text(function(candidate) {
return candidate.choice + " " + candidate.value + "%";
});
candidateWrapper.append("div")
.classed("bar", true)
.transition()
.duration(1000)
.style("width", function(candidate) {
return candidate.value * 10 + "px";
});
}
</script>
</body>
</html>