From b47a70d8b8d8b3ad1783b8ed816eab54a1991e95 Mon Sep 17 00:00:00 2001 From: Ken Johnson Date: Sun, 7 Dec 2025 02:27:06 -0500 Subject: [PATCH] Fix Google Charts race condition in bar graph view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bar graph was calling drawChart3() before Google Charts library finished loading, causing "Cannot read properties of undefined (reading 'arrayToDataTable')" error. Applied same fix as performance page: - Check if visualization already loaded before calling google.load - Use callback parameter to ensure charts only draw after load - Add flag to prevent duplicate library loads - Guard against missing DOM elements - Handle AJAX-loaded partial context Fixes dashboard statistics bar graph view errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/views/dashboard/bar_graph.html.erb | 121 ++++++++++++++++--------- 1 file changed, 76 insertions(+), 45 deletions(-) diff --git a/app/views/dashboard/bar_graph.html.erb b/app/views/dashboard/bar_graph.html.erb index ed8c550..8c8041c 100644 --- a/app/views/dashboard/bar_graph.html.erb +++ b/app/views/dashboard/bar_graph.html.erb @@ -1,54 +1,85 @@ -
- +
+ + \ No newline at end of file +function initializeBarChart() { + // Check if Google Charts visualization is already loaded + if (typeof google !== 'undefined' && google.visualization && google.visualization.ColumnChart) { + drawChart3(); + window.barChartLoaded = true; + } else if (typeof google !== 'undefined' && google.load && !window.barChartLoaded) { + // Load Google Charts + google.load("visualization", "1", { + packages: ["corechart"], + callback: function() { + drawChart3(); + window.barChartLoaded = true; + } + }); + } else { + console.error('Google JSAPI not available'); + } +} + +// Initialize immediately (page is already loaded when this partial loads via AJAX) +initializeBarChart(); +