-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
143 lines (115 loc) · 3.51 KB
/
Copy pathindex.html
File metadata and controls
143 lines (115 loc) · 3.51 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
.chart{
width: 70%;
}
</style>
</head>
<body>
<div class="chart">
<canvas id="myChart"></canvas>
<table id="chartTable"></table>
</div>
</body>
<script>
$(document).ready(function () {
console.log('loop started')
setInterval(()=> {ajaxCall()}, 5000)
})
function creatngChart(xValues, yValues){
console.log('min value:', Math.min(...yValues))
console.log('min value:', Math.max(...yValues), Math.max(...yValues)+200)
new Chart("myChart", {
type: "line",
data: {
labels: xValues,
datasets: [{
label: 'Black',
fill: false,
lineTension: 0,
backgroundColor: "black",
borderColor: "black",
data: yValues
}]
},
options: {
title: {display: true, text: 'Chart'},
legend: {display: true},
scales: {
yAxes: [{ ticks: { min: Math.min(...yValues)-200, max: Math.max(...yValues)+200 }
}],
}
}
});
console.log('repeating')
}
function ajaxCall() {
var xValues = [];
var yValues = [];
var settings = {
"url": "http://51.143.8.209:8000/Recorded/Data/6",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Token f8de65723ef921d1fe4556210570c7334e2580d4"
},
};
$.ajax(settings).done(function (response) {
console.log(response[0].captured_date)
for(var i=0; i<=response.length-1; i++){
xValues.push(response[i].captured_date);
yValues.push(response[i].ledger_id)
}
creatngChart(xValues, yValues)
creatingTable(response);
});
}
function creatingTable(resp) {
let table = document.getElementById('chartTable')
let data = Object.keys(resp[0]);
generateTableHead(table, data);
generateTable(table, resp);
}
function generateTableHead(table, data) {
let thead = table.createTHead();
let row = thead.insertRow();
for (let key of data) {
if(key=='captured_date' || key=='ledger_id'){
console.log(key)
let th = document.createElement("th");
if(key=='captured_date'){
let text = document.createTextNode('Captured Date');;
th.appendChild(text);
row.appendChild(th);
}
if(key=='ledger_id'){
let text = document.createTextNode('Ledger Id');;
th.appendChild(text);
row.appendChild(th);
}
}
}
}
function generateTable(table, data) {
for (let element of data) {
let row = table.insertRow();
for (key in element) {
if(key=='captured_date' || key=='ledger_id'){
console.log('data', element[key])
let cell = row.insertCell();
let text = document.createTextNode(element[key]);
cell.appendChild(text);
}
}
}
$("table, th, td").css({"border": "1px solid black", "width": "50%", "border-collapse": "collapse", "text-align": "center"});
$("th, td").css({"padding": "15px"})
}
</script>
</html>