My goal is to be able to generate something exactly like this.
var data = google.visualization.arrayToDataTable([
['Year', 'Cost'],
['2004', 1000],
['2005', 1170],
['2006', 660],
['2007', 1030]
]);
But I am trying to get it done by using data that is generated by JSON
{
"uid": 1,
"name": "Cost",
"data": [
{
"year": 2009,
"cost": 640
},
{
"year": 2010,
"cost": 620
},
{
"year": 2011,
"cost": 600
},
{
"year": 2012,
"cost": 620
}
]
}
And by using this jQuery
$.getJSON("js/cost.json", function(d) {
console.log(d.data);
var items = [];
$.each( d.data, function( k, v ) {
console.log(v.cost);
console.log(v.year);
items.push("['"+v.year+"',"+v.cost+"]");
});
console.log(items);
});
But what I'm noticing is that its being pushed as a string, what is the correct way to push objects to an array so I can get this working.