gyrogpsc/static/scripts/speedChart.js
2021-01-13 13:16:59 +01:00

78 lines
1.9 KiB
JavaScript

let allSpeedsSerial = []
let ctx = document.getElementById('speedChart').getContext('2d');
let speedChart = new Chart(ctx, {
type: 'line',
data: {
labels: new Array(),
datasets: [{
label: 'Ublox speed',
backgroundColor: 'rgba(214, 69, 65, 1)',
borderColor: 'rgba(214, 69, 65, 1)',
borderWidth: 1,
fill: false,
pointRadius: 0.5,
lineTension: 0.5,
data: []
},
{
label: 'Smartphone speed',
backgroundColor: 'rgba(30, 139, 195, 1)',
borderColor: 'rgba(30, 139, 195, 1)',
borderWidth: 1,
fill: false,
pointRadius: 0.5,
lineTension: 0.5,
data: []
}]
},
options: {
scales: {
yAxes: [{
ticks: {
min: 0,
max: 250,
stepSize: 25
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'second'
}
}]
},
animation: {
duration: 0
}
}
});
function addSerialSpeedData() {
let speeds = []
indexes.forEach(index => {
speeds.push((allSpeedsSerial[index] * 3.6).toFixed(2))
})
speedChart.data.datasets[0].data = speeds;
speedChart.update();
}
function addTCPSpeedData(sensordataList) {
let speedsTCP = []
let times = []
sensordataList.forEach(sensordata => {
if (sensordata.Speed === 0) {
return;
}
let speed = sensordata.Speed
speedsTCP.push((speed * 3.6).toFixed(2));
let time = sensordata.Servertime
times.push(time)
})
speedChart.data.labels = times;
speedChart.data.datasets[1].data = speedsTCP;
speedChart.update();
}