-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
89 lines (72 loc) · 2.46 KB
/
script.js
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
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(getData);
google.charts.setOnLoadCallback(getData2);
// Create a new request object
function getData(){
let request = new XMLHttpRequest()
// TODO: URL to contact goes here
let requestUrl = "https://api.eia.gov/series/?api_key=f8f3fad1c1fe690549b8b646d4429af3&series_id=SEDS.REPRB.FL.A"
// Open a connection
request.open('GET', requestUrl, true)
// Callback for when the request completes
request.onload = function(){
let theActualData = JSON.parse(request.response).series[0].data
renewableProd(theActualData)
}
// Callback for when there's an error
request.error = function(err){
console.log("error is: ", err)
}
// Send the request to the specified URL
request.send()
}
function renewableProd(freshData) {
freshData.unshift(["Year", "Billion BTUs"])
var data = google.visualization.arrayToDataTable(freshData);
var options = {
title: 'Renewable Energy Production in Florida',
curveType: 'function',
legend: { position: 'bottom' },
reverseCategories: true,
backgroundColor: '#e6ffee'
};
var chart = new google.visualization.LineChart(document.getElementById('chart1'));
chart.draw(data, options);
$(window).resize(function(){
renewableProd();
});
}
function getData2(){
let request = new XMLHttpRequest()
// TODO: URL to contact goes here
let requestUrl = "https://api.eia.gov/series/?api_key=f8f3fad1c1fe690549b8b646d4429af3&series_id=SEDS.TETCB.FL.A"
// Open a connection
request.open('GET', requestUrl, true)
// Callback for when the request completes
request.onload = function(){
let theActualData = JSON.parse(request.response).series[0].data
energyConsum(theActualData)
}
// Callback for when there's an error
request.error = function(err){
console.log("error is: ", err)
}
// Send the request to the specified URL
request.send()
}
function energyConsum(freshData) {
freshData.unshift(["Year", "Billion BTUs"])
var data = google.visualization.arrayToDataTable(freshData);
var options = {
title: 'Electricity Total Consumption (i.e. sold) in Florida',
curveType: 'function',
legend: { position: 'bottom' },
reverseCategories: true,
backgroundColor: '#e6ffee'
};
var chart = new google.visualization.LineChart(document.getElementById('chart2'));
chart.draw(data, options);
$(window).resize(function(){
energyConsum();
});
}