Skip to content

Instantly share code, notes, and snippets.

@RainismZ
Last active October 18, 2017 17:18
Show Gist options
  • Save RainismZ/8e8d4c8677ac04f92b6c8e56ebfcc138 to your computer and use it in GitHub Desktop.
Save RainismZ/8e8d4c8677ac04f92b6c8e56ebfcc138 to your computer and use it in GitHub Desktop.
English Premier League Visualization
license: mit

English Premier League 03-04

English Premier League (03-04) W/L data. I’m an Arsenal fan and my team accomplished an undefeated season in 03-04 so I choose this set ;) URL / Downloadable CSV

This line chart is about the North London rivals Arsenal(red) and Tottenham(blue) league points from week 1 to week 38 (Arsenal 90 points in week 38 and Tottenham 45 points).

Forked from d3noob’s Block.

<!DOCTYPE html>
<meta charset="utf-8">
<style> /* set the CSS */
.line {
fill: none;
stroke: steelblue;
stroke-width: 2px;
}
</style>
<body>
<!-- load the d3.js library -->
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
// set the dimensions and margins of the graph
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 640 - margin.left - margin.right,
height = 360 - margin.top - margin.bottom;
// set the ranges
var x = d3.scaleLinear().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
// define the 1st line
var valueline = d3.line()
.x(function(d) { return x(d.Week); })
.y(function(d) { return y(d.Tottenham); });
// define the 2nd line
var valueline2 = d3.line()
.x(function(d) { return x(d.Week); })
.y(function(d) { return y(d.Arsenal); });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Get the data
d3.csv("resultByWeek.csv", function(error, data) {
if (error) throw error;
// format the data
data.forEach(function(d) {
d.Week = + d.Week;
d.Tottenham = +d.Tottenham;
d.Arsenal = +d.Arsenal;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.Week; }));
y.domain([0, d3.max(data, function(d) {
return Math.max(d.Tottenham, d.Arsenal); })]);
// Add the valueline path.
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
// Add the valueline2 path.
svg.append("path")
.data([data])
.attr("class", "line")
.style("stroke", "red")
.attr("d", valueline2);
// Add the X Axis
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// Add the Y Axis
svg.append("g")
.call(d3.axisLeft(y));
});
</script>
</body>
Week Arsenal Tottenham
1 3 0
2 6 3
3 9 4
4 12 5
5 13 5
6 14 5
7 17 6
8 20 9
9 23 12
10 24 13
11 27 13
12 30 13
13 33 16
14 34 16
15 35 19
16 38 19
17 39 19
18 42 19
19 45 19
20 46 22
21 49 25
22 52 28
23 55 28
24 58 31
25 61 34
26 64 35
27 67 35
28 70 38
29 73 38
30 74 38
31 77 38
32 78 38
33 81 39
34 82 39
35 83 39
36 84 39
37 87 42
38 90 45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment