-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph3.js
51 lines (50 loc) · 1.66 KB
/
graph3.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
"use strict";
(function () {
window.onload = function() {
var slider = document.getElementById("slider");
var output = document.getElementById("value");
output.innerHTML = slider.value; // Display the default slider value
displayGraph(2003);
slider.oninput = function() {
output.innerHTML = this.value;
displayGraph(this.value);
}
}
function displayGraph(year) {
var url ="https://raw.githubusercontent.com/pathiratk/india-lights-analysis/master/3/" + year + ".json";
$.getJSON(url, function(json) {
var spec = {
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"mark": {
"type": "bar",
"point": true
},
"title": {
"text": "Difference in Monthly Light Outputs between the Capital Districts and the Other Districts in " + year
},
"data": {
"values": json
},
"encoding": {
"x": {
"field": "state",
"type": "nominal",
"axis": {
"title": "State"
}
},
"y": {
"field": "value",
"type": "quantitative",
"aggregate":"median",
"axis": {
"title": "Difference in monthly light outputs"
}
}
// "color": {"field": "state", "type": "nominal"}
}
};
vegaEmbed('#view', spec, {defaultStyle: true}).catch(console.warn);
});
}
})();