我需要做一个非常简单的Web应用程序,该应用程序从json中获取一些值并将它们绘制在带有Google图表的对偶图表中。 我能够从json中获取数据,但图表中没有任何内容。 我认为我在合并范围方面有问题,但我无法弄清楚它的实际作用...
这是我的代码:
function drawChart() {
var fila = [];
var json = $.ajax({
url: "js/fooData.jsonp",
type: "GET",
dataType: "jsonp",
crossDomain: true,
jsonpCallback: "foo",
success: function (jsonData) {
for (var i = 0; i < jsonData.length; i++) {
fila[i] = Object.values(jsonData[i]);
fila[i].push(fila)
}
}
});
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'CO2');
data.addColumn('number', 'H2S');
data.addRows(fila);
var options = {
title: 'title',
width: 900,
height: 500,
// Gives each series an axis that matches the vAxes number below.
series: {
0: {targetAxisIndex: 0},
1: {targetAxisIndex: 1}
},
vAxes: {
// Adds titles to each axis.
0: {title: 'CO2 flux'},
1: {title: 'H2S'}
},
hAxis: {
ticks: [2004, 2005, 2006, 2007]
},
vAxis: {
viewWindow: {
max: 1200
}
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
google.charts.load("visualization", "1", {packages:["corechart"], callback: drawChart});
这是json文件:
foo([
{"year":"2004", "hola":1000, "adios":400},
{"year":"2005", "hola":1170, "adios":460},
{"year":"2006", "hola":660, "adios":1120},
{"year":"2007", "hola":1030, "adios":540}
])
非常感谢您的帮助 谢谢。