-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchart2.html
More file actions
72 lines (66 loc) · 2.05 KB
/
chart2.html
File metadata and controls
72 lines (66 loc) · 2.05 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Chart two</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="container" style="height: 400px;"></div>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script type="text/javascript">
$.getJSON('http://cdn.rawgit.com/ejb/highcharts-tutorial/master/data/poll-data.json', function(data){
// create three empty series to add our data into
var highchartsFormat = [
{
name: "Conservatives",
data: []
},
{
name: "Labour",
data: []
},
{
name: "Liberal Democrats",
data: []
}
];
// loop through each line of the spreadsheet...
$.each(data, function(i, row){
// .. create a Unix timestamp for each row ...
var dateArr = row.date.split('-');
var timestamp = Date.UTC( +dateArr[2], +dateArr[1]-1, +dateArr[0] );
// ... and add to the Highcharts-formatted data object
highchartsFormat[0].data.push([ timestamp, row["CON"] ]);
highchartsFormat[1].data.push([ timestamp, row["LAB"] ]);
highchartsFormat[2].data.push([ timestamp, row["LIB DEM"] ]);
});
// then create the chart
$('#container').highcharts({
series: highchartsFormat,
xAxis: {
type: 'datetime' // required, or the x axis is rendered as numbers
},
credits: {
enabled: false // removes Highcharts.com in bottom
},
title: {
text: 'Guardian/ICM poll results over time'
},
yAxis: {
title: null, // disables unnecessary title on y axis
labels: {
formatter: function(){ // this function is run once for each label
if (this.isLast){
return this.value+'%'; // add % sign to the top y axis label
}
return this.value;
}
}
},
colors: ['#03529E', '#9E0400', '#FDB009'] // set party colours
});
});
</script>
</body>
</html>