Chart = null;
            }
        }

        function loadDeviceAnalytics(deviceId, period) {
            fetch(`/analytics/devices/${deviceId}?period=${period}`)
                .then(response => {
                    if (!response.ok) {
                        throw new Error('Failed to load device analytics');
                    }
                    return response.json();
                })
                .then(data => {
                    currentDeviceData = data;
                    displayDevic