-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
73 lines (52 loc) · 1.48 KB
/
main.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
function ajaxGetRequest(path, callback) {
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState===4 && this.status ===200) {
callback(this.response);
}
}
request.open("GET", path);
request.send();
}
function ajaxPostRequest(path, data, callback){
let request = new XMLHttpRequest();
request.onreadystatechange = function(){
if (this.readyState === 4 && this.status === 200){
callback(this.response);
}
};
request.open("POST", path);
request.send(data);
}
function BarGraph(response){
response = JSON.parse(response)
var layout = {
title:"Cities By Suicide Rates",
xaxis:{title:"Suicide Rates"},
yaxis:{title:"Cities"}
}
Plotly.newPlot(document.getElementById("bar"),response,layout)
}
function PieGraph(response){
response = JSON.parse(response)
var layout = {
title:"Suicide Rates By Year",
}
Plotly.newPlot(document.getElementById("pie"), response,layout);
}
function post(){
ajaxPostRequest("/makePie2", JSON.stringify({"Key":"value"}), PieGraph);
}
function postR(){
ajaxPostRequest("/makePie3", JSON.stringify({"Key":"value"}), PieGraph);
}
function postB2(){
ajaxPostRequest("/makeBar2", JSON.stringify({"Bar":2}), BarGraph);
}
function postBR(){
ajaxPostRequest("/makeBarR", JSON.stringify({"Bar":2}), BarGraph);
}
function getData(){
ajaxGetRequest("/makeBar",BarGraph);
ajaxGetRequest("/makePie",PieGraph);
}