I'd like to use this code to parse JSON data from a Yahoo finance CSV file. The JSON link is valid, I'm just having trouble with the function (data)
and var data
lines. The parse table calls for function (data)
but that conflicts with the var data
line. The original code I used to parse the table had used function (json)
, but this specific api seems to only work with the function (data)
.
function drawTable() {
// use jQuery to make an AJAX request for data
$.ajax({
type: "get",
dataType: "jsonp",
url: 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quoteslist%20where%20symbol%3D%27BRDT%2CAPPL%27&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',
success: function (data) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Symbol');
data.addColumn('number', 'open');
// parse the JSON into the DataTable
for (var i = 0; i < json.list.resources.length; i++) {
var symbol = json.list.resources[i].resource.fields.symbol;
var open = parseFloat(json.list.resources[i].resource.fields.open);
data.addRow([symbol, open]);
}
var table = new google.visualization.Table(document.querySelector('#table_div'));
table.draw(data);
}
});
}
google.load('visualization', '1', {
packages: ['table'],
callback: drawTable
});