-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_old.html
106 lines (87 loc) · 2.6 KB
/
index_old.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
103
104
105
106
<title>Democratic Party Exit Polls</title>
<style>
.left-labels,
.labels {
font-family: sans-serif;
font-size: 10px;
}
.chart-title {
font-family:sans-serif;
font-size: 16px;
text-anchor: middle;
font-weight: bold;
}
.footer {
font-family:sans-serif;
}
</style>
<script src="//d3js.org/d3.v3.min.js"></script>
<body>
<div id="graph-container"></div>
<div class="footer">
<p>Exit Poll Data: <a href="http://data.cnn.com/jsonp/ELECTION/2016/OH/xpoll/Pfull.json">2012 Ohio CNN</a>
<a href="http://data.cnn.com/jsonp/ELECTION/2016/OH/xpoll/Pfull.json">2016 Ohio CNN</a>
<script>
var width = 800;
var height = 800;
var margin = {top: 20, bottom: 20, left: 100, right:100};
var leftScale = d3.scale.linear()
.domain([0.0, 1.0])
.range([height - margin.top, margin.bottom]);
var rightScale = d3.scale.linear()
.domain([0.0, 1.0])
.range([height - margin.top, margin.bottom]);
var currencyFormatter = d3.format("0,.0f");
var svg = d3.select("#graph-container")
.append("svg")
.attr("width", width)
.attr("height", height);
d3.csv('data/ohio_exit_polls.csv', function(d) {
data = d;
var lines = svg.selectAll("line")
.data(data);
lines.enter()
.append("line")
.attr("x1", margin.left)
.attr("x2", width - margin.right)
.attr("y1", function(d) {
return leftScale(parseFloat(d['2012']));
})
.attr("y2", function(d) {
return rightScale(parseFloat(d['2016']));
})
.attr("stroke", "black")
.attr("stroke-width", 1);
var rightLabels = svg.selectAll(".labels")
.data(data);
rightLabels.enter()
.append("text")
.attr("class","labels")
.attr("x", width - margin.right + 3)
.attr("y", function(d) {
return rightScale(parseFloat(d['2016'])) + 4;
})
.text(function (d) {
return d['Category'];
});
var leftLabels = svg.selectAll(".left-labels")
.data(data);
leftLabels.enter()
.append("text")
.attr("class","left-labels")
.attr("x", margin.left - 65)
.attr("y", function(d) {
return leftScale(parseFloat(d['2012'])) + 4;
})
.text(function (d) {
return d['Category'];
})
.style("text-anchor","begin");
svg.append("text")
.attr("x", width / 2)
.attr("y", margin.top)
.attr("class", "chart-title")
.text("CNN Exit Polls, Democratic Party 2012 and 2016");
});
</script>
</body>