Skip to content

Commit d51c104

Browse files
committed
Fix Chart.js loading issues with reliable CDN and add error handling
1 parent 47f71d0 commit d51c104

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

flights/stats.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h3>Most Frequent Airlines</h3>
8888
const flightRoutesData = {{ site.data.flightRoutes | jsonify }};
8989
</script>
9090

91-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
91+
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.umd.js"></script>
9292
<script src="{{ '/js/flight-stats.js' | relative_url }}"></script>
9393

9494
<style>

js/flight-stats.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,30 @@ class FlightStatsCalculator {
309309

310310
// Initialize when DOM is loaded
311311
document.addEventListener('DOMContentLoaded', function() {
312+
console.log('DOM loaded, checking for data...');
313+
312314
if (typeof locationsData !== 'undefined' && typeof flightRoutesData !== 'undefined') {
313-
new FlightStatsCalculator(locationsData, flightRoutesData);
315+
console.log('Data found, initializing calculator...');
316+
console.log('Locations:', locationsData.length);
317+
console.log('Flights:', flightRoutesData.length);
318+
319+
try {
320+
new FlightStatsCalculator(locationsData, flightRoutesData);
321+
console.log('FlightStatsCalculator initialized successfully');
322+
} catch (error) {
323+
console.error('Error initializing FlightStatsCalculator:', error);
324+
}
325+
} else {
326+
console.error('Required data is missing:', {
327+
locationsData: typeof locationsData,
328+
flightRoutesData: typeof flightRoutesData
329+
});
330+
}
331+
332+
// Check if Chart.js is loaded
333+
if (typeof Chart === 'undefined') {
334+
console.error('Chart.js is not loaded!');
335+
} else {
336+
console.log('Chart.js is loaded successfully');
314337
}
315338
});

0 commit comments

Comments
 (0)