-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloridavotes.html
78 lines (70 loc) · 2.01 KB
/
floridavotes.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Test</title>
<script type="text/javascript" src="d3/d3.v3.js"></script>
</head>
<body>
<h4>The Florida Senate voted to strike down a proposed reform to health care.</h4>
<script type="text/javascript">
//Width and height
//Bar chart!---------------------------------------------------
var w = 200;
var h = 200;
var barPadding = 1;
var dataset = [41, 72];
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", function(d, i) {
return i * (w / dataset.length);
})
.attr("y", function(d) {
return h - d * 2;
})
.attr("width", w / dataset.length - barPadding)
.attr("height", function(d) {
return d * 2 - 25;
})
.attr("fill", function(d) {
return "teal";
});
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.text(function(d) {
return d;
})
.attr("text-anchor", "middle")
.attr("x", function(d, i) {
return i * (w / dataset.length) + (w / dataset.length - barPadding) / 2;
})
.attr("y", function(d) {
return h - 30;
})
.attr("font-family", "sans-serif")
.attr("font-size", "24px")
.attr("fill", "white");
var axisScale = d3.scale.ordinal()
.domain(["For", "Opposed"])
.rangeRoundBands([0, w]);
var xAxis = d3.svg.axis()
.scale(axisScale)
.orient("bottom")
.ticks(2);
svg.append("g")
.attr("class", "axis")
.attr("font-family", "sans-serif")
.attr("transform", "translate(0, " + (h - 25) + ")")
.call(xAxis);
</script>
</body>
</html>