I'm using the following code to request for json file and parsing it
google.load('visualization', '1', {packages: ['controls', "motionchart", "table"]});
google.setOnLoadCallback(function(){
createTable($('#chart_div').width(),400);
})
var jsonData;
$.ajax({
url: shapingTomorrowDataUrl,
dataType: "json",
async: true,
success: function(data) {
console.log("Data done");
jsonData=data;
createTable($('#chart_div').width(),400);
}
});
Now I initially used a synchronous call to json file and it worked perfectly. But now my client wants a loader gif to play while the data is being read. Synchronous request caused the gif to hang a lot. But my problem with asynchronous request is that on the first time that the user opens my dashboard, the chart function gets called before the json data is parsed. I changed the code a bit to call the function in the success function and commenting the callbackfunction.
But this causes the following error to pop up:
Uncaught TypeError: Cannot read property 'DataTable' of undefined
in the following line:
var chartData = new google.visualization.DataTable();
So in essence my code only works after the first try i.e I'm guessing after the json file is stored in cache. During the first try, the loader gif keeps playing without ever drawing the chart. Would really appreciate some advice on how to solve it.