I've been struggling for a long time to connect this array to a Google chart with no success. I would really appreciate some assistance in identifying what mistake I've made. I have created a jsfiddle where the array appears to be correct, and when manually copied and pasted into the chart, it works fine. Therefore, the issue seems to be with the code not processing correctly.
google.load("visualization", "1", {
packages: ["corechart"]
});
google.setOnLoadCallback(drawChart);
function drawChart() {
var dataset = $.ajax({
url: 'http://data.sparkfun.com/output/AJ2p4r8Owvt1MyV8q9MV.json?page=1',
type: 'get',
dataType: 'jsonp',
crossDomain: true,
success: function (jsonObj) {
var arr = ["[['Time', 'Humidity', 'Temp']"];
$.each(jsonObj, function (i, tObj) {
arr.push("['" + tObj.stationtime + "', " + tObj.humidity + ', ' + tObj.temp + ']');
});
arr.push("]")
// This for debugging
document.getElementById("demo").innerHTML = arr;
}
});
var data = google.visualization.arrayToDataTable([
dataset
]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}