出于某种原因,以下代码未提供预期的谷歌散点图。JSON url 具有两个表变量的数字输出。任何线索(顺便说一下,JSON 确实适用于饼图,包括一个字符串变量而不是散点图的数字变量)。
$(function() {
// when document loads, grab the json
$.getJSON(jsonurl, function(data) {
// once grabbed, we run this callback
// setup the new table and its data
var data = new google.visualization.DataTable();
data.addRows(data.rows.length); // length gives us the number of results in our returned data
data.addColumn('number', 'meterprijs');
data.addColumn('number', 'perceeloppervlak');
// now we need to build the map data, loop over each result
$.each(data.rows, function(i,v) {
// set the values for both the name and the population
data.setValue(i, 0, v.a1_meterprijs);
data.setValue(i, 1, v.a1_buitenopp);
});
// finally, create the map!
var options = {
title: 'Age vs. Weight comparison',
hAxis: {title: 'Meterprijs', minValue: 1500, maxValue: 6000},
vAxis: {title: 'Perceelopp', minValue: 10, maxValue: 1000},
legend: 'none'
};
var chart = new google.visualization.ScatterChart(
document.getElementById('visualization2'));
chart.draw(data, options);
});
});
});
});