let allSpeedsSerial = [] var ctx = document.getElementById('speedChart').getContext('2d'); var 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: 1, lineTension: 0.5, data: [] }, { label: 'Smartphone speed', backgroundColor: 'rgba(30, 139, 195, 1)', borderColor: 'rgba(30, 139, 195, 1)', borderWidth: 1, fill: false, pointRadius: 1, 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(); console.log("speeds serial " + speeds.length) } 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) }) console.log("speeds tcp " + speedsTCP.length) speedChart.data.labels = times; speedChart.data.datasets[1].data = speedsTCP; speedChart.update(); }