在bubble_minor.js中,我试图将因霍乱而死亡的人数放在mapData数组的对象中,如值:22。这意味着死亡人数为22.虽然我能够将这个属性推到那些mapData数组,但是当我试图在地图上绘制那些死亡计数时,它没有显示出来。为此,我尝试使用hasOwnProperty检查mapData是否具有value属性,结果显示“undefined”。如果我在我的Mapdata中查找控制台,我可以看到添加的value属性。我不知道为什么hasOwnProperty(value)在行号-474上未定义
$(document).ready(function(){
$('#button1').click(function(){
$("#chartdiv").fadeIn();
$('#chart').hide();
//var selected_value=$('#dropDownId :selected').val();
//console.log(selected_value);
var mapData = [
{"code":"AF" , "name":"Afghanistan", "color":"#eea638"},
{"code":"AL" , "name":"Albania", "color":"#d8854f"},
{"code":"DZ" , "name":"Algeria", "color":"#de4c4f"},
{"code":"AO" , "name":"Angola", "color":"#de4c4f"},
{"code":"AR" , "name":"Argentina", "color":"#86a965"},
{"code":"AM" , "name":"Armenia", "color":"#d8854f"},
{"code":"AU" , "name":"Australia", "color":"#8aabb0"},
{"code":"AT" , "name":"Austria", "color":"#d8854f"},
{"code":"AZ" , "name":"Azerbaijan", "color":"#d8854f"},
{"code":"BH" , "name":"Bahrain", "color":"#eea638"},
{"code":"BD" , "name":"Bangladesh", "color":"#eea638"},
{"code":"BY" , "name":"Belarus", "color":"#d8854f"},
{"code":"BE" , "name":"Belgium", "color":"#d8854f"},
{"code":"BJ" , "name":"Benin", "color":"#de4c4f"},
{"code":"BT" , "name":"Bhutan", "color":"#eea638"},
{"code":"BO" , "name":"Bolivia", "color":"#86a965"},
{"code":"BA" , "name":"Bosnia and Herzegovina", "color":"#d8854f"},
{"code":"BW" , "name":"Botswana", "color":"#de4c4f"},
{"code":"BN" , "name":"Brunei", "color":"#eea638"},
{"code":"BG" , "name":"Bulgaria", "color":"#d8854f"},
{"code":"BF" , "name":"Burkina Faso", "color":"#de4c4f"},
{"code":"BI" , "name":"Burundi", "color":"#de4c4f"},
{"code":"KH" , "name":"Cambodia", "color":"#eea638"},
{"code":"CM" , "name":"Cameroon", "color":"#de4c4f"},
{"code":"CA" , "name":"Canada", "color":"#a7a737"},
{"code":"CV" , "name":"Cape Verde", "color":"#de4c4f"},
{"code":"CF" , "name":"Central African Rep.", "color":"#de4c4f"},
{"code":"TD" , "name":"Chad", "color":"#de4c4f"},
{"code":"CL" , "name":"Chile", "color":"#86a965"},
{"code":"CN" , "name":"China", "color":"#eea638"},
{"code":"CO" , "name":"Colombia", "color":"#86a965"},
{"code":"KM" , "name":"Comoros", "color":"#de4c4f"},
{"code":"CD" , "name":"Congo, Dem. Rep.", "color":"#de4c4f"},
{"code":"CG" , "name":"Congo, Rep.", "color":"#de4c4f"},
{"code":"CR" , "name":"Costa Rica", "color":"#a7a737"},
{"code":"CI" , "name":"Cote d'Ivoire", "color":"#de4c4f"},
{"code":"HR" , "name":"Croatia", "color":"#d8854f"},
{"code":"CU" , "name":"Cuba", "color":"#a7a737"},
{"code":"CY" , "name":"Cyprus", "color":"#d8854f"},
{"code":"CZ" , "name":"Czech Rep.", "color":"#d8854f"},
{"code":"DK" , "name":"Denmark", "color":"#d8854f"},
{"code":"DJ" , "name":"Djibouti", "color":"#de4c4f"},
{"code":"DO" , "name":"Dominican Rep.", "color":"#a7a737"},
{"code":"EC" , "name":"Ecuador", "color":"#86a965"},
{"code":"EG" , "name":"Egypt", "color":"#de4c4f"},
{"code":"SV" , "name":"El Salvador", "color":"#a7a737"},
{"code":"GQ" , "name":"Equatorial Guinea", "color":"#de4c4f"},
{"code":"ER" , "name":"Eritrea", "color":"#de4c4f"},
{"code":"EE" , "name":"Estonia", "color":"#d8854f"},
{"code":"ET" , "name":"Ethiopia", "color":"#de4c4f"},
{"code":"FJ" , "name":"Fiji", "color":"#8aabb0"},
{"code":"FI" , "name":"Finland", "color":"#d8854f"},
{"code":"FR" , "name":"France", "color":"#d8854f"},
{"code":"GA" , "name":"Gabon", "color":"#de4c4f"},
{"code":"GM" , "name":"Gambia", "color":"#de4c4f"},
{"code":"GE" , "name":"Georgia", "color":"#d8854f"},
{"code":"DE" , "name":"Germany", "color":"#d8854f"},
{"code":"GH" , "name":"Ghana", "color":"#de4c4f"},
{"code":"GR" , "name":"Greece", "color":"#d8854f"},
{"code":"GT" , "name":"Guatemala", "color":"#a7a737"},
{"code":"GN" , "name":"Guinea", "color":"#de4c4f"},
{"code":"GW" , "name":"Guinea-Bissau", "color":"#de4c4f"},
{"code":"GY" , "name":"Guyana", "color":"#86a965"},
{"code":"HT" , "name":"Haiti", "color":"#a7a737"},
{"code":"HN" , "name":"Honduras", "color":"#a7a737"},
{"code":"HK" , "name":"Hong Kong, China", "color":"#eea638"},
{"code":"HU" , "name":"Hungary", "color":"#d8854f"},
{"code":"IS" , "name":"Iceland", "color":"#d8854f"},
{"code":"IN" , "name":"India", "color":"#eea638"},
{"code":"ID" , "name":"Indonesia", "color":"#eea638"},
{"code":"IR" , "name":"Iran", "color":"#eea638"},
{"code":"IQ" , "name":"Iraq", "color":"#eea638"},
{"code":"IE" , "name":"Ireland", "color":"#d8854f"},
{"code":"IL" , "name":"Israel", "color":"#eea638"},
{"code":"IT" , "name":"Italy", "color":"#d8854f"},
{"code":"JM" , "name":"Jamaica", "color":"#a7a737"},
{"code":"JP" , "name":"Japan", "color":"#eea638"},
{"code":"JO" , "name":"Jordan", "color":"#eea638"},
{"code":"KZ" , "name":"Kazakhstan", "color":"#eea638"},
{"code":"KE" , "name":"Kenya", "color":"#de4c4f"},
{"code":"KP" , "name":"Korea, Dem. Rep.", "color":"#eea638"},
{"code":"KR" , "name":"Korea, Rep.", "color":"#eea638"},
{"code":"KW" , "name":"Kuwait", "color":"#eea638"},
{"code":"KG" , "name":"Kyrgyzstan", "color":"#eea638"},
{"code":"LA" , "name":"Laos", "color":"#eea638"},
{"code":"LV" , "name":"Latvia", "color":"#d8854f"},
{"code":"LB" , "name":"Lebanon", "color":"#eea638"},
{"code":"LS" , "name":"Lesotho", "color":"#de4c4f"},
{"code":"LR" , "name":"Liberia", "color":"#de4c4f"},
{"code":"LY" , "name":"Libya", "color":"#de4c4f"},
{"code":"LT" , "name":"Lithuania", "color":"#d8854f"},
{"code":"LU" , "name":"Luxembourg", "color":"#d8854f"},
{"code":"MK" , "name":"Macedonia, FYR", "color":"#d8854f"},
{"code":"MG" , "name":"Madagascar", "color":"#de4c4f"},
{"code":"MW" , "name":"Malawi", "color":"#de4c4f"},
{"code":"MY" , "name":"Malaysia", "color":"#eea638"},
{"code":"ML" , "name":"Mali", "color":"#de4c4f"},
{"code":"BR" , "name":"Brazil", "color":"#86a965"},
{"code":"MR" , "name":"Mauritania", "color":"#de4c4f"},
{"code":"MU" , "name":"Mauritius", "color":"#de4c4f"},
{"code":"MX" , "name":"Mexico", "color":"#a7a737"},
{"code":"MD" , "name":"Moldova", "color":"#d8854f"},
{"code":"MN" , "name":"Mongolia", "color":"#eea638"},
{"code":"ME" , "name":"Montenegro", "color":"#d8854f"},
{"code":"MA" , "name":"Morocco", "color":"#de4c4f"},
{"code":"MZ" , "name":"Mozambique", "color":"#de4c4f"},
{"code":"MM" , "name":"Myanmar", "color":"#eea638"},
{"code":"NA" , "name":"Namibia", "color":"#de4c4f"},
{"code":"NP" , "name":"Nepal", "color":"#eea638"},
{"code":"NL" , "name":"Netherlands", "color":"#d8854f"},
{"code":"NZ" , "name":"New Zealand", "color":"#8aabb0"},
{"code":"NI" , "name":"Nicaragua", "color":"#a7a737"},
{"code":"NE" , "name":"Niger", "color":"#de4c4f"},
{"code":"NG" , "name":"Nigeria", "color":"#de4c4f"},
{"code":"NO" , "name":"Norway", "color":"#d8854f"},
{"code":"OM" , "name":"Oman", "color":"#eea638"},
{"code":"PK" , "name":"Pakistan", "color":"#eea638"},
{"code":"PA" , "name":"Panama", "color":"#a7a737"},
{"code":"PG" , "name":"Papua New Guinea", "color":"#8aabb0"},
{"code":"PY" , "name":"Paraguay", "color":"#86a965"},
{"code":"PE" , "name":"Peru", "color":"#86a965"},
{"code":"PH" , "name":"Philippines", "color":"#eea638"},
{"code":"PL" , "name":"Poland", "color":"#d8854f"},
{"code":"PT" , "name":"Portugal", "color":"#d8854f"},
{"code":"PR" , "name":"Puerto Rico", "color":"#a7a737"},
{"code":"QA" , "name":"Qatar", "color":"#eea638"},
{"code":"RO" , "name":"Romania", "color":"#d8854f"},
{"code":"RU" , "name":"Russian", "color":"#d8854f"},
{"code":"RW" , "name":"Rwanda", "color":"#de4c4f"},
{"code":"SA" , "name":"Saudi Arabia", "color":"#eea638"},
{"code":"SN" , "name":"Senegal", "color":"#de4c4f"},
{"code":"RS" , "name":"Serbia", "color":"#d8854f"},
{"code":"SL" , "name":"Sierra Leone", "color":"#de4c4f"},
{"code":"SG" , "name":"Singapore", "color":"#eea638"},
{"code":"SK" , "name":"Slovak Republic", "color":"#d8854f"},
{"code":"SI" , "name":"Slovenia", "color":"#d8854f"},
{"code":"SB" , "name":"Solomon Islands", "color":"#8aabb0"},
{"code":"SO" , "name":"Somalia", "color":"#de4c4f"},
{"code":"ZA" , "name":"South Africa", "color":"#de4c4f"},
{"code":"ES" , "name":"Spain", "color":"#d8854f"},
{"code":"LK" , "name":"Sri Lanka", "color":"#eea638"},
{"code":"SD" , "name":"Sudan", "color":"#de4c4f"},
{"code":"SR" , "name":"Suriname", "color":"#86a965"},
{"code":"SZ" , "name":"Swaziland", "color":"#de4c4f"},
{"code":"SE" , "name":"Sweden", "color":"#d8854f"},
{"code":"CH" , "name":"Switzerland", "color":"#d8854f"},
{"code":"SY" , "name":"Syria", "color":"#eea638"},
{"code":"TW" , "name":"Taiwan", "color":"#eea638"},
{"code":"TJ" , "name":"Tajikistan", "color":"#eea638"},
{"code":"TZ" , "name":"Tanzania", "color":"#de4c4f"},
{"code":"TH" , "name":"Thailand", "color":"#eea638"},
{"code":"TG" , "name":"Togo", "color":"#de4c4f"},
{"code":"TT" , "name":"Trinidad and Tobago", "color":"#a7a737"},
{"code":"TN" , "name":"Tunisia", "color":"#de4c4f"},
{"code":"TR" , "name":"Turkey", "color":"#d8854f"},
{"code":"TM" , "name":"Turkmenistan", "color":"#eea638"},
{"code":"UG" , "name":"Uganda", "color":"#de4c4f"},
{"code":"UA" , "name":"Ukraine", "color":"#d8854f"},
{"code":"AE" , "name":"United Arab Emirates", "color":"#eea638"},
{"code":"GB" , "name":"United Kingdom", "color":"#d8854f"},
{"code":"US" , "name":"United States", "color":"#a7a737"},
{"code":"UY" , "name":"Uruguay", "color":"#86a965"},
{"code":"UZ" , "name":"Uzbekistan", "color":"#eea638"},
{"code":"VE" , "name":"Venezuela", "color":"#86a965"},
{"code":"PS" , "name":"West Bank and Gaza", "color":"#eea638"},
{"code":"VN" , "name":"Vietnam", "color":"#eea638"},
{"code":"YE" , "name":"Yemen, Rep.", "color":"#eea638"},
{"code":"ZM" , "name":"Zambia", "color":"#de4c4f"},
{"code":"ZW" , "name":"Zimbabwe", "color":"#de4c4f"}];
$.ajax({
url:'http://apps.who.int/gho/athena/data/GHO/CHOLERA_0000000002.json?profile=simple&filter=COUNTRY:*;REGION:*',
type:'GET',
timeout:100000,
success:function (response) {
console.log(response);
console.log(response.fact.length);
for(i=0;i<response.fact.length;i++){
for(x in response.fact[i].dim){
var internal_data=response.fact[i].dim;
if(internal_data[x]==2008){
deaths=response.fact[i].Value;
console.log(response.fact[i], "Deaths by this"+" "+deaths);
for(k=0;k<mapData.length;k++){
if(mapData[k].name==internal_data.COUNTRY){
console.log(mapData[k].name);
//mapData.push(deaths);
mapData[k].value= parseInt(deaths);
}
else{
//delete mapData[k];
}
}
}
}
}
console.log(mapData);
}
});
var latlong = {};
latlong["AD"] = {"latitude":42.5, "longitude":1.5};
latlong["AE"] = {"latitude":24, "longitude":54};
latlong["AF"] = {"latitude":33, "longitude":65};
latlong["AG"] = {"latitude":17.05, "longitude":-61.8};
latlong["AI"] = {"latitude":18.25, "longitude":-63.1667};
latlong["AL"] = {"latitude":41, "longitude":20};
latlong["AM"] = {"latitude":40, "longitude":45};
latlong["AN"] = {"latitude":12.25, "longitude":-68.75};
latlong["AO"] = {"latitude":-12.5, "longitude":18.5};
latlong["AP"] = {"latitude":35, "longitude":105};
latlong["AQ"] = {"latitude":-90, "longitude":0};
latlong["AR"] = {"latitude":-34, "longitude":-64};
latlong["AS"] = {"latitude":-14.3333, "longitude":-170};
latlong["AT"] = {"latitude":47.3333, "longitude":13.3333};
latlong["AU"] = {"latitude":-27, "longitude":133};
latlong["AW"] = {"latitude":12.5, "longitude":-69.9667};
latlong["AZ"] = {"latitude":40.5, "longitude":47.5};
latlong["BA"] = {"latitude":44, "longitude":18};
latlong["BB"] = {"latitude":13.1667, "longitude":-59.5333};
latlong["BD"] = {"latitude":24, "longitude":90};
latlong["BE"] = {"latitude":50.8333, "longitude":4};
latlong["BF"] = {"latitude":13, "longitude":-2};
latlong["BG"] = {"latitude":43, "longitude":25};
latlong["BH"] = {"latitude":26, "longitude":50.55};
latlong["BI"] = {"latitude":-3.5, "longitude":30};
latlong["BJ"] = {"latitude":9.5, "longitude":2.25};
latlong["BM"] = {"latitude":32.3333, "longitude":-64.75};
latlong["BN"] = {"latitude":4.5, "longitude":114.6667};
latlong["BO"] = {"latitude":-17, "longitude":-65};
latlong["BR"] = {"latitude":-10, "longitude":-55};
latlong["BS"] = {"latitude":24.25, "longitude":-76};
latlong["BT"] = {"latitude":27.5, "longitude":90.5};
latlong["BV"] = {"latitude":-54.4333, "longitude":3.4};
latlong["BW"] = {"latitude":-22, "longitude":24};
latlong["BY"] = {"latitude":53, "longitude":28};
latlong["BZ"] = {"latitude":17.25, "longitude":-88.75};
latlong["CA"] = {"latitude":54, "longitude":-100};
latlong["CC"] = {"latitude":-12.5, "longitude":96.8333};
latlong["CD"] = {"latitude":0, "longitude":25};
latlong["CF"] = {"latitude":7, "longitude":21};
latlong["CG"] = {"latitude":-1, "longitude":15};
latlong["CH"] = {"latitude":47, "longitude":8};
latlong["CI"] = {"latitude":8, "longitude":-5};
latlong["CK"] = {"latitude":-21.2333, "longitude":-159.7667};
latlong["CL"] = {"latitude":-30, "longitude":-71};
latlong["CM"] = {"latitude":6, "longitude":12};
latlong["CN"] = {"latitude":35, "longitude":105};
latlong["CO"] = {"latitude":4, "longitude":-72};
latlong["CR"] = {"latitude":10, "longitude":-84};
latlong["CU"] = {"latitude":21.5, "longitude":-80};
latlong["CV"] = {"latitude":16, "longitude":-24};
latlong["CX"] = {"latitude":-10.5, "longitude":105.6667};
latlong["CY"] = {"latitude":35, "longitude":33};
latlong["CZ"] = {"latitude":49.75, "longitude":15.5};
latlong["DE"] = {"latitude":51, "longitude":9};
latlong["DJ"] = {"latitude":11.5, "longitude":43};
latlong["DK"] = {"latitude":56, "longitude":10};
latlong["DM"] = {"latitude":15.4167, "longitude":-61.3333};
latlong["DO"] = {"latitude":19, "longitude":-70.6667};
latlong["DZ"] = {"latitude":28, "longitude":3};
latlong["EC"] = {"latitude":-2, "longitude":-77.5};
latlong["EE"] = {"latitude":59, "longitude":26};
latlong["EG"] = {"latitude":27, "longitude":30};
latlong["EH"] = {"latitude":24.5, "longitude":-13};
latlong["ER"] = {"latitude":15, "longitude":39};
latlong["ES"] = {"latitude":40, "longitude":-4};
latlong["ET"] = {"latitude":8, "longitude":38};
latlong["EU"] = {"latitude":47, "longitude":8};
latlong["FI"] = {"latitude":62, "longitude":26};
latlong["FJ"] = {"latitude":-18, "longitude":175};
latlong["FK"] = {"latitude":-51.75, "longitude":-59};
latlong["FM"] = {"latitude":6.9167, "longitude":158.25};
latlong["FO"] = {"latitude":62, "longitude":-7};
latlong["FR"] = {"latitude":46, "longitude":2};
latlong["GA"] = {"latitude":-1, "longitude":11.75};
latlong["GB"] = {"latitude":54, "longitude":-2};
latlong["GD"] = {"latitude":12.1167, "longitude":-61.6667};
latlong["GE"] = {"latitude":42, "longitude":43.5};
latlong["GF"] = {"latitude":4, "longitude":-53};
latlong["GH"] = {"latitude":8, "longitude":-2};
latlong["GI"] = {"latitude":36.1833, "longitude":-5.3667};
latlong["GL"] = {"latitude":72, "longitude":-40};
latlong["GM"] = {"latitude":13.4667, "longitude":-16.5667};
latlong["GN"] = {"latitude":11, "longitude":-10};
latlong["GP"] = {"latitude":16.25, "longitude":-61.5833};
latlong["GQ"] = {"latitude":2, "longitude":10};
latlong["GR"] = {"latitude":39, "longitude":22};
latlong["GS"] = {"latitude":-54.5, "longitude":-37};
latlong["GT"] = {"latitude":15.5, "longitude":-90.25};
latlong["GU"] = {"latitude":13.4667, "longitude":144.7833};
latlong["GW"] = {"latitude":12, "longitude":-15};
latlong["GY"] = {"latitude":5, "longitude":-59};
latlong["HK"] = {"latitude":22.25, "longitude":114.1667};
latlong["HM"] = {"latitude":-53.1, "longitude":72.5167};
latlong["HN"] = {"latitude":15, "longitude":-86.5};
latlong["HR"] = {"latitude":45.1667, "longitude":15.5};
latlong["HT"] = {"latitude":19, "longitude":-72.4167};
latlong["HU"] = {"latitude":47, "longitude":20};
latlong["ID"] = {"latitude":-5, "longitude":120};
latlong["IE"] = {"latitude":53, "longitude":-8};
latlong["IL"] = {"latitude":31.5, "longitude":34.75};
latlong["IN"] = {"latitude":20, "longitude":77};
latlong["IO"] = {"latitude":-6, "longitude":71.5};
latlong["IQ"] = {"latitude":33, "longitude":44};
latlong["IR"] = {"latitude":32, "longitude":53};
latlong["IS"] = {"latitude":65, "longitude":-18};
latlong["IT"] = {"latitude":42.8333, "longitude":12.8333};
latlong["JM"] = {"latitude":18.25, "longitude":-77.5};
latlong["JO"] = {"latitude":31, "longitude":36};
latlong["JP"] = {"latitude":36, "longitude":138};
latlong["KE"] = {"latitude":1, "longitude":38};
latlong["KG"] = {"latitude":41, "longitude":75};
latlong["KH"] = {"latitude":13, "longitude":105};
latlong["KI"] = {"latitude":1.4167, "longitude":173};
latlong["KM"] = {"latitude":-12.1667, "longitude":44.25};
latlong["KN"] = {"latitude":17.3333, "longitude":-62.75};
latlong["KP"] = {"latitude":40, "longitude":127};
latlong["KR"] = {"latitude":37, "longitude":127.5};
latlong["KW"] = {"latitude":29.3375, "longitude":47.6581};
latlong["KY"] = {"latitude":19.5, "longitude":-80.5};
latlong["KZ"] = {"latitude":48, "longitude":68};
latlong["LA"] = {"latitude":18, "longitude":105};
latlong["LB"] = {"latitude":33.8333, "longitude":35.8333};
latlong["LC"] = {"latitude":13.8833, "longitude":-61.1333};
latlong["LI"] = {"latitude":47.1667, "longitude":9.5333};
latlong["LK"] = {"latitude":7, "longitude":81};
latlong["LR"] = {"latitude":6.5, "longitude":-9.5};
latlong["LS"] = {"latitude":-29.5, "longitude":28.5};
latlong["LT"] = {"latitude":55, "longitude":24};
latlong["LU"] = {"latitude":49.75, "longitude":6};
latlong["LV"] = {"latitude":57, "longitude":25};
latlong["LY"] = {"latitude":25, "longitude":17};
latlong["MA"] = {"latitude":32, "longitude":-5};
latlong["MC"] = {"latitude":43.7333, "longitude":7.4};
latlong["MD"] = {"latitude":47, "longitude":29};
latlong["ME"] = {"latitude":42.5, "longitude":19.4};
latlong["MG"] = {"latitude":-20, "longitude":47};
latlong["MH"] = {"latitude":9, "longitude":168};
latlong["MK"] = {"latitude":41.8333, "longitude":22};
latlong["ML"] = {"latitude":17, "longitude":-4};
latlong["MM"] = {"latitude":22, "longitude":98};
latlong["MN"] = {"latitude":46, "longitude":105};
latlong["MO"] = {"latitude":22.1667, "longitude":113.55};
latlong["MP"] = {"latitude":15.2, "longitude":145.75};
latlong["MQ"] = {"latitude":14.6667, "longitude":-61};
latlong["MR"] = {"latitude":20, "longitude":-12};
latlong["MS"] = {"latitude":16.75, "longitude":-62.2};
latlong["MT"] = {"latitude":35.8333, "longitude":14.5833};
latlong["MU"] = {"latitude":-20.2833, "longitude":57.55};
latlong["MV"] = {"latitude":3.25, "longitude":73};
latlong["MW"] = {"latitude":-13.5, "longitude":34};
latlong["MX"] = {"latitude":23, "longitude":-102};
latlong["MY"] = {"latitude":2.5, "longitude":112.5};
latlong["MZ"] = {"latitude":-18.25, "longitude":35};
latlong["NA"] = {"latitude":-22, "longitude":17};
latlong["NC"] = {"latitude":-21.5, "longitude":165.5};
latlong["NE"] = {"latitude":16, "longitude":8};
latlong["NF"] = {"latitude":-29.0333, "longitude":167.95};
latlong["NG"] = {"latitude":10, "longitude":8};
latlong["NI"] = {"latitude":13, "longitude":-85};
latlong["NL"] = {"latitude":52.5, "longitude":5.75};
latlong["NO"] = {"latitude":62, "longitude":10};
latlong["NP"] = {"latitude":28, "longitude":84};
latlong["NR"] = {"latitude":-0.5333, "longitude":166.9167};
latlong["NU"] = {"latitude":-19.0333, "longitude":-169.8667};
latlong["NZ"] = {"latitude":-41, "longitude":174};
latlong["OM"] = {"latitude":21, "longitude":57};
latlong["PA"] = {"latitude":9, "longitude":-80};
latlong["PE"] = {"latitude":-10, "longitude":-76};
latlong["PF"] = {"latitude":-15, "longitude":-140};
latlong["PG"] = {"latitude":-6, "longitude":147};
latlong["PH"] = {"latitude":13, "longitude":122};
latlong["PK"] = {"latitude":30, "longitude":70};
latlong["PL"] = {"latitude":52, "longitude":20};
latlong["PM"] = {"latitude":46.8333, "longitude":-56.3333};
latlong["PR"] = {"latitude":18.25, "longitude":-66.5};
latlong["PS"] = {"latitude":32, "longitude":35.25};
latlong["PT"] = {"latitude":39.5, "longitude":-8};
latlong["PW"] = {"latitude":7.5, "longitude":134.5};
latlong["PY"] = {"latitude":-23, "longitude":-58};
latlong["QA"] = {"latitude":25.5, "longitude":51.25};
latlong["RE"] = {"latitude":-21.1, "longitude":55.6};
latlong["RO"] = {"latitude":46, "longitude":25};
latlong["RS"] = {"latitude":44, "longitude":21};
latlong["RU"] = {"latitude":60, "longitude":100};
latlong["RW"] = {"latitude":-2, "longitude":30};
latlong["SA"] = {"latitude":25, "longitude":45};
latlong["SB"] = {"latitude":-8, "longitude":159};
latlong["SC"] = {"latitude":-4.5833, "longitude":55.6667};
latlong["SD"] = {"latitude":15, "longitude":30};
latlong["SE"] = {"latitude":62, "longitude":15};
latlong["SG"] = {"latitude":1.3667, "longitude":103.8};
latlong["SH"] = {"latitude":-15.9333, "longitude":-5.7};
latlong["SI"] = {"latitude":46, "longitude":15};
latlong["SJ"] = {"latitude":78, "longitude":20};
latlong["SK"] = {"latitude":48.6667, "longitude":19.5};
latlong["SL"] = {"latitude":8.5, "longitude":-11.5};
latlong["SM"] = {"latitude":43.7667, "longitude":12.4167};
latlong["SN"] = {"latitude":14, "longitude":-14};
latlong["SO"] = {"latitude":10, "longitude":49};
latlong["SR"] = {"latitude":4, "longitude":-56};
latlong["ST"] = {"latitude":1, "longitude":7};
latlong["SV"] = {"latitude":13.8333, "longitude":-88.9167};
latlong["SY"] = {"latitude":35, "longitude":38};
latlong["SZ"] = {"latitude":-26.5, "longitude":31.5};
latlong["TC"] = {"latitude":21.75, "longitude":-71.5833};
latlong["TD"] = {"latitude":15, "longitude":19};
latlong["TF"] = {"latitude":-43, "longitude":67};
latlong["TG"] = {"latitude":8, "longitude":1.1667};
latlong["TH"] = {"latitude":15, "longitude":100};
latlong["TJ"] = {"latitude":39, "longitude":71};
latlong["TK"] = {"latitude":-9, "longitude":-172};
latlong["TM"] = {"latitude":40, "longitude":60};
latlong["TN"] = {"latitude":34, "longitude":9};
latlong["TO"] = {"latitude":-20, "longitude":-175};
latlong["TR"] = {"latitude":39, "longitude":35};
latlong["TT"] = {"latitude":11, "longitude":-61};
latlong["TV"] = {"latitude":-8, "longitude":178};
latlong["TW"] = {"latitude":23.5, "longitude":121};
latlong["TZ"] = {"latitude":-6, "longitude":35};
latlong["UA"] = {"latitude":49, "longitude":32};
latlong["UG"] = {"latitude":1, "longitude":32};
latlong["UM"] = {"latitude":19.2833, "longitude":166.6};
latlong["US"] = {"latitude":38, "longitude":-97};
latlong["UY"] = {"latitude":-33, "longitude":-56};
latlong["UZ"] = {"latitude":41, "longitude":64};
latlong["VA"] = {"latitude":41.9, "longitude":12.45};
latlong["VC"] = {"latitude":13.25, "longitude":-61.2};
latlong["VE"] = {"latitude":8, "longitude":-66};
latlong["VG"] = {"latitude":18.5, "longitude":-64.5};
latlong["VI"] = {"latitude":18.3333, "longitude":-64.8333};
latlong["VN"] = {"latitude":16, "longitude":106};
latlong["VU"] = {"latitude":-16, "longitude":167};
latlong["WF"] = {"latitude":-13.3, "longitude":-176.2};
latlong["WS"] = {"latitude":-13.5833, "longitude":-172.3333};
latlong["YE"] = {"latitude":15, "longitude":48};
latlong["YT"] = {"latitude":-12.8333, "longitude":45.1667};
latlong["ZA"] = {"latitude":-29, "longitude":24};
latlong["ZM"] = {"latitude":-15, "longitude":30};
latlong["ZW"] = {"latitude":-20, "longitude":30};
console.log(mapData);
// get min and max values
var minBulletSize = 10;
var maxBulletSize = 70;
var min = Infinity;
var max = -Infinity;
for ( var i = 0; i < mapData.length; i++ ) {
var shrt=mapData[i];
if(shrt.hasOwnProperty(value)){
};
console.log(mapData[i].value);
var value = mapData[ i ].value;
if ( value < min ) {
min = value;
}
if ( value > max ) {
max = value;
}
}
// it's better to use circle square to show difference between values, not a radius
var maxSquare = maxBulletSize * maxBulletSize * 2 * Math.PI;
var minSquare = minBulletSize * minBulletSize * 2 * Math.PI;
// create circle for each country
var images = [];
for ( var i = 0; i < mapData.length; i++ ) {
var dataItem = mapData[ i ];
var value = dataItem.value;
console.log(value);
// calculate size of a bubble
var square = ( value - min ) / ( max - min ) * ( maxSquare - minSquare ) + minSquare;
if ( square < minSquare ) {
square = minSquare;
}
var size = Math.sqrt( square / ( Math.PI * 2 ) );
var id = dataItem.code;
images.push( {
"type": "circle",
"theme": "light",
"width": size,
"height": size,
"color": dataItem.color,
"longitude": latlong[ id ].longitude,
"latitude": latlong[ id ].latitude,
"title": dataItem.name ,
"value": value
} );
}
console.log('fesfewfew');
// build map
var map = AmCharts.makeChart( "chartdiv", {
"type": "map",
"projection": "eckert3", //miller
"titles": [ {
"text": "Number of reported deaths from cholera ",
"size": 14
}, {
"text": "source: WHO",
"size": 11
} ],
"areasSettings": {
//"unlistedAreasColor": "#000000",
//"unlistedAreasAlpha": 0.1
},
"dataProvider": {
"map": "worldLow",
"images": images
},
"export": {
"enabled": true
}
} );
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<html>
<head>
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src ="bubble_minor.js"></script>
<link rel="stylesheet" type="text/css" href="bubble_minor.css">
</head>
<body>
<div id="chartdiv"><h1>Welcome</h1></div>
<input id="button1" type="button" value="Click to get the data of 2008!" />
<div id="chart"></div>
</body>
答案 0 :(得分:0)
有几个问题。
1)hasOwnProperty
需要一个字符串(或ES2015 / ES6 /的符号)。在您的情况下,您需要$Sample1
G1 G2 Group
1 1.016673 -1.04402692 1
2 1.019958 -0.86763046 1
3 1.033050 -1.09717438 1
4 1.036969 0.26971351 1
5 1.044059 1.73402959 1
1 1.053269 -1.04460950 2
2 1.059461 -0.86711232 2
3 1.072446 -1.09748431 2
4 1.078763 0.26785751 2
5 1.038325 1.73818175 2
$Sample2
G1 G2 Group
1 1.413218 0.22466456 1
2 1.413339 -0.91755436 1
3 1.415782 -0.23471118 1
4 1.434750 -0.77498973 1
5 1.436905 0.76642626 1
1 1.438067 0.22933986 2
2 1.856085 -0.91988726 2
3 1.415782 -0.23405677 2
4 1.434750 -0.77406530 2
5 1.436905 0.76078091 2
,然后您可能希望将最小/最大分配移动到hasOwnProperty。
2)AJAX请求(即您的shrt.hasOwnProperty('value')
调用)是异步的,这意味着它们将与其余代码同时运行。您可能会遇到竞争条件,因为您的循环在请求自行解析之前正在运行,导致在运行$.ajax
调用时未定义该数据。您希望将地图创建逻辑包装在函数中并在console.log
回调中调用它,以确保在运行其余代码之前填充mapData变量,例如:
success
这可以修复大部分未定义的输出。请注意,并非每个国家/地区都有数据,因为您的 $.ajax({
url: 'http://apps.who.int/gho/athena/data/GHO/CHOLERA_0000000002.json?profile=simple&filter=COUNTRY:*;REGION:*',
dataType: 'json',
type: 'GET',
timeout: 100000,
success: function(response) {
// all of your initialization code omitted for brevity
makeMap(mapData);
}
});
function makeMap(mapData) {
//everything from var latlong down to the makeChart call goes here
}
未与JSON有效负载name
值对齐,因此您需要进行一些调整以同步这两个起来。您仍会在日志中看到未定义的行,但现在生成的地图会有更多不同的圈子。