You could try replacing $(document).ready(function () {...}); with google.setOnLoadCallback(function () {...}); which would provide
similar but not quite the same functionality. Given the complexity of your set up, there could be issues with doing that.
Alternatively, you could wrap the drawing function inside another, which first loads the API and then issues the callback to draw when the API is loaded:
function initCharts (tbl) {
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(function () {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Visiteurs');
data.addRows(tbl.length);
for (var i = 0; i < tbl.length; i++) {
data.setValue(i, 0, tbl[i].date);
data.setValue(i, 1, tbl[i].nbVisits);
}
var chart = new google.visualization.LineChart(document.getElementById('chartDiv'));
chart.draw(data, {
left: 50,
top: 0,
width: 570,
height: 330,
chartArea: {
left:80,
top:20,
width:500,
height:250
},
legend: 'none',
hAxis: {
showTextEvery: 4
/*, slantedText: true*/
}
});
});
}
Then change all the drawChart(tbl) calls to initChart(tbl). The loader is smart enough to know when the API has already been loaded, so when you call it a second time, it skips the loading and initiates the callback function again, so there should be little to no performance impact on your site.