let allSpeedsSerial = [] let indexes = [] var arrayTCP = []; var arraySERIAL = []; var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'line', data: { labels: new Array(), datasets: [{ label: 'Ublox', backgroundColor: 'rgba(214, 69, 65, 1)', borderColor: 'rgba(214, 69, 65, 1)', borderWidth: 1, fill: false, pointRadius: 1, lineTension: 0.5, data: arraySERIAL }, { label: 'Smartphone', backgroundColor: 'rgba(30, 139, 195, 1)', borderColor: 'rgba(30, 139, 195, 1)', borderWidth: 1, fill: false, pointRadius: 1, lineTension: 0.5, data: arrayTCP }] }, 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)) }) myChart.data.datasets[0].data = speeds; myChart.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) }) myChart.data.labels = times; myChart.data.datasets[1].data = speedsTCP; myChart.update(); } function findSerialDataIndex(tcpdataList, serialdataList) { let allSerialTimes = [] serialdataList.forEach(sensordata => { if (!(sensordata.Speed === 0)) { let serialTimestamp; allSpeedsSerial.push(sensordata.Speed) serialTimestamp = composeServertime(sensordata.Servertime) allSerialTimes.push(serialTimestamp) } }) tcpdataList.forEach(sensordata => { if (!(sensordata.Speed === 0)) { let tcpTimestamp = composeServertime(sensordata.Servertime) let index = findBestTimeMatch(tcpTimestamp, allSerialTimes)[1] indexes.push(index) } }) console.log("indexes: " + indexes) }