-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
106 lines (88 loc) · 3.04 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawBarChart);
google.charts.setOnLoadCallback(drawScatterPlot);
google.charts.setOnLoadCallback(drawPieChart);
google.charts.setOnLoadCallback(drawPieChart2);
function drawBarChart() {
let locations= utility_data.map(
function(item){
var locAndSize = [item.BuildingName, parseInt(item.BuildingSizeSQFT)];
return locAndSize;
}
);
locations.unshift(['Building Name', 'Building Size']);
const data = google.visualization.arrayToDataTable(locations);
// Set Options
const options = {
title: 'Building Size at NYIT Campuses'
};
// Draw
const chart = new google.visualization.BarChart(document.getElementById('barChart'));
chart.draw(data, options);
}
function drawScatterPlot() {
let locations= utility_data.map(
function(item){
var locAndSize = [ parseInt(item.BuildingSizeSQFT), parseFloat(item.TotalCost)];
return locAndSize;
}
);
locations.unshift(['Building Name', 'Building Size']);
const data = google.visualization.arrayToDataTable(locations);
// Set Options
const options = {
title: 'Size vs Cost'
};
// Draw
const chart = new google.visualization.ScatterChart(document.getElementById('scatterPlot'));
chart.draw(data, options);
}
function drawPieChart() {
let locations= utility_data.map(
function(item){
var locAndSize = [ item.BuildingName, parseFloat(item.TotalConsumption)];
return locAndSize;
}
);
locations.unshift(['Building Name', 'Consumption']);
const data = google.visualization.arrayToDataTable(locations);
// Set Options
const options = {
title: 'Consumption by Building',
is3D: true
};
// Draw
const chart = new google.visualization.PieChart(document.getElementById('pieChart'));
chart.draw(data, options);
}
function drawPieChart2() {
let tempData = summarizeConsumptionByCity(utility_data);
const data = google.visualization.arrayToDataTable(tempData);
// Set Options
const options = {
title: 'Consumption by City',
is3D: true
};
// Draw
const chart = new google.visualization.PieChart(document.getElementById('pieChart2'));
chart.draw(data, options);
}
function summarizeConsumptionByCity(data) {
const cityData = {};
// Iterate over the array of JSON objects
data.forEach(item => {
const city = item.AddressCity;
const consumption = item.TotalConsumption;
// If the city is not in the cityData object, add it
if (!cityData[city]) {
cityData[city] = 0;
}
// Add the consumption to the city's total
cityData[city] += parseFloat(consumption);
});
// Convert the cityData object to a 2D array
const result = Object.entries(cityData).map(([city, totalConsumption]) => [city, totalConsumption]);
result.unshift(['City', 'Consumption'])
console.log(result);
return result;
}