我正在从我的API动态添加数据到Google地理图表,但是出现了错误:"Error: Not an array"
有人可以在我的代码中找到错误吗?
MyApi.php
function Mappa($sesso, $anno){
header('Content-Type: application/json');
require('../php/config.php');
#CONNESSIONE AL DATABASE
$con=mysqli_connect("localhost", "root", "xxxx", "xxx");
// Check connection
if (mysqli_connect_errno()) #SE C'È UN ERRORE DI CONNESSIONE, MI FERMO SUBITO
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$recordsTot=array();
$recordsTot = select($mysqli,"SELECT Country, Value AS data FROM disMondiale WHERE SUBJECT='$sesso' AND TIME='$anno'");
foreach($results as $result)
{
$geo_chart_data[] = array($recordsTot['Country'], (int)$recordsTot['data']);
}
return json_encode($geo_chart_data);
}
getByTotMappa.php
require('MyAPI.php');
if(! isset($_REQUEST['anno'])) exit();
$anno = $_REQUEST['anno'];
echo Mappa("LRHUTTTT", $anno);
JS代码
function Mappa(node, anno){
var annoC=anno;
$.getJSON("./api/getByTotMappa.php?anno="+annoC+"&src=", function(data)
{
creaMappa(data, node)
});
}
function creaMappa(data,node){
google.setOnLoadCallback(drawRegionsMap(data,node));
}
function drawRegionsMap(series, node) {
var data = google.visualization.arrayToDataTable({series});
var options = {colorAxis: {colors: ['#FFFFFF', '#048ABF', '#025172', '#023E5A', '#013453']}};
var chart = new google.visualization.GeoChart(document.getElementById('#'+node));
chart.draw(data, options);
}
初始化
$(document).ready(function() {
google.load('visualization', '1.0', {'packages':['geochart']});
var node = "container";
Mappa(node,2011);
});
我做错了什么?