-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (95 loc) · 2.56 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,700' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
shape-rendering: crispEdges;
width:100%;
}
.bar {
fill: #006c8e;
}
.bargroup text {
font-size: 16px;
fill: #ccc;
}
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
.x.axis path {
display: none;
}
#bar-10 rect {
fill: #55b7d9;
}
#bar-10 text {
fill: #000;
}
</style>
<body>
<svg class="chart"></svg>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 20, right: 30, bottom: 30, left: 40},
width = 550 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.range([height, 0]);
// var xAxis = d3.svg.axis()
// .scale(x)
// .orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var chart = d3.select(".chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("data/yearlysnowtotals.csv", type, function(error, data) {
x.domain(data.map(function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.total; })]);
// chart.append("g")
// .attr("class", "x axis")
// .attr("transform", "translate(0," + height + ")")
// .call(xAxis);
chart.append("g")
.attr("class", "y axis")
.call(yAxis);
chart.selectAll(".bar")
.data(data)
.enter().append("g")
.attr("class", "bargroup")
.attr("id", function(d, i) { return "bar-" + i;})
.append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.date); })
.attr("y", function(d) { return y(d.total); })
.attr("height", function(d) { return height - y(d.total); })
.attr("width", x.rangeBand());
chart.selectAll(".bargroup")
.data(data)
.append("text")
.attr("x", -340)
.attr("y", function(d) { return x(d.date) + ( x.rangeBand() / 2 )})
.attr("dy", ".35em")
.attr("transform", "rotate(-90)")
.text(function(d) { return d.date });
});
function type(d) {
d.total = +d.total; // coerce to number
return d;
}</script>