// Chart.js inicializálása const ctx = document.getElementById('realtimeChart').getContext('2d'); const realtimeChart = new Chart(ctx, { type: 'line', data: { labels: chartLabels, datasets: [{ label: 'Szenzor Érték', data: chartData, borderColor: 'rgb(75, 192, 192)', tension: 0.1, fill: false }] }, options: { scales: { x: { type: 'time', // Idő alapú X tengely time: { unit: 'second' } }, y: { beginAtZero: true } } } });
socket.on('connect', function() { console.log('Kapcsolódva a Socket.IO szerverhez'); });
socket.on('new_data', function(msg) { console.log('Fogadott adat:', msg); document.getElementById('currentValue').textContent = msg.value.toFixed(2);
// Adatok hozzáadása a grafikonhoz const time = new Date(msg.timestamp * 1000); // Unix timestampből Date objektum chartLabels.push(time); chartData.push(msg.value);
if (chartLabels.length > MAX_DATA_POINTS) { chartLabels.shift(); // Régi adatok törlése chartData.shift(); }
realtimeChart.update(); // Grafikon frissítése });
socket.on('disconnect', function() { console.log('Lecsatlakozva a Socket.IO szerverről'); });