0
我在我的應用程序中使用Google地理圖表。 我正在複製數據庫數據鏈接中給出的示例。Google Geo Charts:無法使用json數據繪製圖表
https://developers.google.com/chart/interactive/docs/gallery/geochart?hl=en
的數據數組是
var data = google.visualization.arrayToDataTable([
['City', 'Population', 'Area'],
['Rome', 2761477, 1285.31]])
在格式
。
我給與數據變量類似模式的數據。但看不到圖表。
var arr=[];
$.ajax({
type: 'POST',
url: "LiveMap",
dataType: "json",
success: function (response) {
for (var i = 0; i < response.length; i++) {
var temp=[];
var str=response[i].split(':');
temp[0]=str[0];
temp[1]=parseInt(str[1]);
temp[2]=parseInt(str[2]);
arr[i]=temp;
}
}
});
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = new google.visualization.DataTable();
data.addColumn("string","City");
data.addColumn("number","Population");
data.addColumn("number","Area");
data.addRows(arr);
var options = {
region: 'IT',
displayMode: 'markers',
colorAxis: {colors: ['green', 'blue']}
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 300px; height: 300px;"></div>
</body>
</html>
到AJAX調用的響應是
result.put("Bhopal:300:200");
result.put("Hyderabad:300:200");
result.put("Vizag:300:200");
result.put("Mysore:300:200");
result.put("Delhi:300:200")
;