javascript - Google charts not showing at first request, but on second only -
i'm using google charts visualise company performance data. javascript looks follows:
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart","line","geochart"], "callback": drawallcompanycharts}); function drawallcompanycharts() { drawchart(); drawlinechart(); drawdonutchart(); drawstackedchart(); drawmarkersmap(); drawchart(); } </script>
when user clicks button show charts page, nothing shown , a
uncaught referenceerror: google not defined
error appears. when clicking button again, charts appear requierd, no errors.
i tried use google.setonloadcallback(drawallcompanycharts);
shown here, drawallcompanycharts()
never gets called. putting in $(document).ready(function () {
didn't make work.
the error indicates google object not ready time need it. it's timing. how can assure drawallcompanycharts()
called when google object ready? , why doesn't google.setonloadcallback(drawallcompanycharts);
show effect?
any highly appreciated :-)
try load https://www.google.com/jsapi
after js code. happened sometime object not found if load js earlier code.
so try interchange there position.
<script type="text/javascript"> google.load("visualization", "1", {packages:["corechart","line","geochart"], "callback": drawallcompanycharts}); function drawallcompanycharts() { drawchart(); drawlinechart(); drawdonutchart(); drawstackedchart(); drawmarkersmap(); drawchart(); } </script> <script type="text/javascript" src="https://www.google.com/jsapi"></script>
or can add timeout request google function.
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> settimeout( function() { google.load("visualization", "1", {packages:["corechart","line","geochart"], "callback": drawallcompanycharts}); function drawallcompanycharts() { drawchart(); drawlinechart(); drawdonutchart(); drawstackedchart(); drawmarkersmap(); drawchart(); } }, 100); </script>
Comments
Post a Comment