我正在尝试使用AJAX和JSON获取的值修改矢量地图。
使用此数组键值完美映射函数:
var visitorsData = {
"tac": 564,
"moq": 400,
"lim": 1000,
"apu": 800,
"caj": 760,
"ama": 300,
"lib": 700,
"lam": 600,
};
获取此值的函数是:
$('#world-map').vectorMap({
map: 'peru',
backgroundColor: '#fff',
regionStyle: {
initial: {
fill: "#c6c6c6",
stroke: "#204d6f",
"stroke-width": 1,
"stroke-opacity": 1
},
hover: {
fill: "#ed0000",
"fill-opacity": "1"
}
},
series: {
regions: [{
values: visitorsData,
scale: ["#3c8dbc", "#2D79A6"], //['#3E5E6B', '#A6BAC2'],
normalizeFunction: 'polynomial'
}]
},
onRegionLabelShow: function(e, el, code) {
if (typeof visitorsData[code] != "undefined")
el.html(el.html() + ': ' + visitorsData[code] + ' new visitors');
}
})
现在我想从JSON获取值并使用此构建新的visitorsData
但没有函数。这是我的代码:
$.ajax({
url: globalMapUrl, //obtain json
})
.done(function(data) {
var visitorsData = new Array();
for (var i = 0; i < data.length; i++) {
var item = data[i];
visitorsData[item.nombre] = item.numeroDeAnuncios;
}
})
.fail(function() {
alert("Ajax failed to fetch data")
})