我试图使用我在www.scb.se(瑞典统计局)的API提取的数据填充谷歌图表。
我使用以下代码:
$.ajax({
type: "POST",
url: 'http://api.scb.se/OV0104/v1/doris/sv/ssd/START/HA/HA0103/Livs',
data: '{"query":[{"code": "Varugrupp","selection":{"filter": "vs:VaruTjänstegrCoicopD","values":["01.1.7"]}},{"code": "ContentsCode","selection": {"filter": "item","values":["HA0103A1"]}},{"code": "Tid","selection":{"filter": "item","values": ["2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014"]}}],"response": {"format": "json"}}',
success: function(data){
console.log(data);
google.charts.load('current', {'packages': ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(){
var jsonData = data;
var options = {
title: 'Company Performance',
curveType: 'function',
legend: { position: 'bottom' }
};
var chartData = google.visualization.arrayToDataTable(jsonData);
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(chartData, options);
}
}
});
当我" console.log(数据)"我可以看到控制台中的所有内容,但图表一直告诉我数据不是数组。我做错了什么?
干杯!
"数据"的控制台日志:
Object {columns: Array[3], comments: Array[1], data: Array[11]}