I'm displaying a Google Charts Pie Chart on a Rails 5 app Page.
The chart only displays if I click refresh, not on the initial page load.
It appears i'm not the first to have this problem, but none of the solutions i've tried have been successful - i.e. setting a timeout.
Any guidance would be much appreciated.
/layouts/application.html.erb
<head>
...
<%= yield :google_chart_scripts %>
...
</head>
/views/organisations/show.html.erb
<% content_for :google_chart_scripts do %>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
            google.charts.setOnLoadCallback(drawChart);
            function drawChart() {
               var data = google.visualization.arrayToDataTable([
                  ['Effort', 'Amount given'],
                  ['Debt', 100.00],
                  ['Equity', 900.00]
               ]);
               var options = {
                  colors:['#f75b52','#363e4a'],
                  pieHole: 0.4,
                  pieSliceText: 'percentage',
                  chartArea: {'width': '90%', 'height': '90%'},
                  legend: 'none'
               };
               var chart = new google.visualization.PieChart(document.getElementById('piechart')%>'));
               chart.draw(data, options);
               }
</script>
<% end %>
 
     
    