I am having trouble displaying google charts from an external JS script, inline script on my HTML works.
I called the loader on the <head> of my HTML file.
And then I have an external JS file (app.js) being loaded as well on my HTML file. This is the content.
$(function() {
google.charts.load('current', {packages: ['corechart']});
google.setOnLoadCallback(drawLineChart);
function drawLineChart(values, labels){
// Define the chart to be drawn.
var data = new google.visualization.DataTable();
var speed = values.speed;
var soc = values.soc;
var dataArray = [];
for (i=0;i<labels.length;i++){
var tempArray = []
tempArray.push(new Date(labels[i]))
tempArray.push(speed[i])
tempArray.push(soc[i])
dataArray.push(tempArray)
}
console.log(dataArray);
data.addColumn('datetime', 'Time of Day');
data.addColumn('number', 'Speed');
data.addColumn('number', 'SOC');
data.addRows(dataArray);
var options = {
legend: { position: 'top', maxLines: 3 }
}
// Instantiate and draw the chart.
var chart = new google.visualization.LineChart(document.getElementById("lineChart"));
console.log("chart: ", chart);
chart.draw(data, options);
}
});
It gives me this error.
jQuery.Deferred exception: google.setOnLoadCallback is not a function TypeError: google.setOnLoadCallback is not a function
Any idea how to load it properly?
Thank you.