Hi Jayme, The loader does (or should) always wait for the window (and document) to be loaded before the callbacks are called. So there *should* be no need for you to check for document onload before proceeding.
But I actually just added a new setting for the 45.2 loader that allows you to ignore the window onload, since some applications need that flexibility. And it appears this was not working properly and it was ignoring the onload always. That may be what you were seeing. I just uploaded a fix for this problem, so it should again be waiting for the window onload. On Wed, Jul 12, 2017 at 9:44 AM, Jayme Jeffman <[email protected]> wrote: > Hello, > > Recently I had a problem caused by the time my page spent to load from the > server. > > The chart object was being created while the page was not fuly loaded yet > , so the container object didn't exists at that time and the chart was not > created due to JavaScript error. > > As you can see at Chart Gallery > <https://developers.google.com/chart/interactive/docs/gallery/>, all > chart examples are simple and the chart object is created while the page is > being loaded. > > I suggest you split the code in two parts, one containing the options > definitions and other containig the call to the library and the callback > method as bellow: > > <html> > <head> > <script type="text/javascript" > src="https://www.gstatic.com/charts/loader.js"></script> > <script type="text/javascript"> > // Options and draw methods definition > function drawChart() { > var data = google.visualization.arrayToDataTable([ > ['Year', 'Sales', 'Expenses'], > ['2004', 1000, 400], > ['2005', 1170, 460], > ['2006', 660, 1120], > ['2007', 1030, 540] > ]); > > var options = { > title: 'Company Performance', > curveType: 'function', > legend: { position: 'bottom' } > }; > > var chart = new > google.visualization.LineChart(document.getElementById('curve_chart')); > > chart.draw(data, options); > } > function pageLoad() > { > google.charts.load('current', {'packages':['corechart']}); > > google.charts.setOnLoadCallback(drawChart); > } > > > > </script> > > </head> > <body onload="pageLoad();"> > <div id="curve_chart" style="width: 900px; height: 500px"></div> > </body> > </html> > > > This way the library will be loaded after the page is fully loaded and all > html objects will have been already created. > > Please let me know if I have made any code heresy. > > Best regards. > > Jayme Jeffman > > > > -- > You received this message because you are subscribed to the Google Groups > "Google Visualization API" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to google-visualization-api@googl > egroups.com. > Visit this group at https://groups.google.com/grou > p/google-visualization-api. > To view this discussion on the web visit https://groups.google.com/d/ms > gid/google-visualization-api/b5094f11-7d92-46ea-b214-145bc63 > 4ae80%40googlegroups.com > <https://groups.google.com/d/msgid/google-visualization-api/b5094f11-7d92-46ea-b214-145bc634ae80%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> [email protected] <[email protected]> 5CC, Cambridge MA -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-visualization-api. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJOuJ2_ArcotMxMwkTawfxyWkdYK8qwCLa-v%3Dn_CH0V8VA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
