Fix Google Charts not rendering with Turbolinks

Removed $(document).ready() wrapper inside google.load callback which
was preventing charts from rendering when page loaded via Turbolinks.

Changes:
- Remove document.ready wrapper (DOM already ready with Turbolinks)
- Add check for element existence before drawing chart
- Add guard to verify google.load exists before calling
- Create separate initializeChart function for cleaner callback

This ensures charts render properly on Turbolinks page loads where
the DOM is already ready when the script executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ken Johnson
2025-12-07 01:09:30 -05:00
parent c6f69b5d69
commit b11c8aed1e
+16 -9
View File
@@ -120,15 +120,22 @@ function makeActive(){
$('li[id="performance"]').addClass('active');
};
// Load Google Charts and set callback
google.load("visualization", "1", {
packages: ["corechart"],
callback: function() {
$(document).ready(function () {
drawChart2();
makeActive();
});
function initializeChart() {
// Check if element exists before drawing
if (document.getElementById('line_chart')) {
drawChart2();
}
});
makeActive();
}
// Load Google Charts and set callback
if (typeof google !== 'undefined' && google.load) {
google.load("visualization", "1", {
packages: ["corechart"],
callback: initializeChart
});
} else {
console.error('Google JSAPI not loaded');
}
</script>