Jvector地图错误:未捕获的错误:尝试使用未加载的地图:world_mill_en

时间:2019-03-26 04:42:20

标签: javascript php mysql json jvectormap

我正在尝试将php MySQL数据的值添加到Jvetor Map中。 我已经获取了JSON格式的值。

我使用的php代码是:

$json_data=array(); 
 foreach($result as $rec)  
{  
$json_array['Country']=$rec['user_country'];  
 $json_array['CountryCode']=$rec['country_code']; 
$json_array['persons']=$rec['usercountry']; 
array_push($json_data,$json_array);  
}  
 $data = json_encode($json_data) ;

我收到的JSON值是:

[
 {"Country":"Australia","CountryCode":"AU","persons":"5"}, 
 {"Country":"Spain","CountryCode":"ES","persons":"2"}, 
 {"Country":"India","CountryCode":"IN","persons":"8"}, 
 {"Country":"Mexico","CountryCode":"MX","persons":"4"},
 {"Country":"United States","CountryCode":"US","persons":"4"}
]

我使用了以下脚本:

<script type="text/javascript">
var dataC = <?php echo $data ?>;
var countryData = {};
$.each(dataC, function() {
countryData[this.CountryCode] = this.persons;
});

$(function() {
$('#world-map').vectorMap({
 map: 'world_mill_en',
 series: {
    regions: [{
        values: countryData, //load the data
        scale: ['#C8EEFF', '#0071A4'],
        normalizeFunction: 'polynomial'}]
  },
  onRegionLabelShow: function(e, el, code) {
    //search through dataC to find the selected country by it's code
    var country =$.grep(dataC, function(obj, index) {
        return obj.CountryCode == code;
    })[0]; //snag the first one
    //only if selected country was found in dataC
    if (country != undefined) { 
       el.html(el.html() + 
            "<br/><b>Code: </b>" +country.CountryCode + 
            "<br/><b>Name: </b>" + country.Country + 
            "<br/><b>persons: </b>" + country.persons);}}
 });
 });
</script>

但是我得到了错误:

  

“未捕获的错误:尝试使用未加载的地图:world_mill_en       在新的jvm.Map上

0 个答案:

没有答案