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:
@@ -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 () {
|
||||
function initializeChart() {
|
||||
// Check if element exists before drawing
|
||||
if (document.getElementById('line_chart')) {
|
||||
drawChart2();
|
||||
makeActive();
|
||||
});
|
||||
}
|
||||
});
|
||||
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>
|
||||
Reference in New Issue
Block a user