-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment_2_visualisation_2.html
83 lines (79 loc) · 2.38 KB
/
assignment_2_visualisation_2.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.axis--x path {
display: none;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
<svg width="1056" height="550"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
margin = {top: 50, right: 50, bottom: 50, left: 50},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
//var parseTime = d3.timeParse("%d-%b-%y");
var x = d3.scaleLinear()
.rangeRound([0, width])
//.tickFormat(d3.format("d"));
var y = d3.scaleLinear()
.rangeRound([height, 0]);
var line = d3.line()
.defined(function(d) {return d.metANN < 100})
.x(function(d) { return x(d.YEAR); })
.y(function(d) { return y(d.metANN); });
d3.csv("example_1_-_station.csv", function(d) {
d.YEAR = +d.YEAR;
d.metANN = +d.metANN;
return d;
}, function(error, data) {
if (error) throw error;
x.domain(d3.extent(data, function(d) { return d.YEAR; }));
y.domain(d3.extent(data, function(d) { if (d.metANN > 100) {
return 0;
} else {
return d.metANN;
}; }));
//y.forceY([7,12])
g.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x).tickFormat(d3.format("d")))
.append("text")
.attr("fill", "#000")
//.attr("transform", "rotate(-90)")
.attr("y", 25)
.attr("dy", "0.71em")
.style("text-anchor", "middle")
.style("font-size", "14px")
.text("Year");
g.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-size", "20px")
.style("text-decoration", "underline")
.text("Geneva Annual Mean Temperatures Graph");
g.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "#000")
.attr("transform", "rotate(-90)")
.attr("y", -35)
.attr("dy", "0.71em")
.style("text-anchor", "end")
.style("font-size", "14px")
.text("Annual Mean Temperatures (degrees celsius)");
g.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
});
</script>