Jvector Map error : Uncaught ReferenceError: jvm is not defined
abnitchauhan opened this issue · comments
Hi there I am trying to fetch the data from the mysql database through php . I have got the values in JSON format but not able to show it in the Vector Map.
Here is my Script :
`<script type="text/javascript">
var dataC = '';
dataC = JSON.parse(dataC) ;
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'}]
},
//-----------------------------------------------
// changed to onRegionLabelShow from onLabelShow
//-----------------------------------------------
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() +
"
Code: " +country.CountryCode +
"
Name: " + country.Country +
"
persons: " + country.persons);}}
});
});
</script>`
The Code is Showing the Error :
Uncaught ReferenceError: jvm is not defined
at w.fn.init.a.fn.vectorMap
Need to import four js files:
- jvectormap/jvectormap.js (binds/registers jvm, but also with jQuery: jvm.$ = jQuery)
- jvectormap/src/map.js (creates jvm.Map constructor)
- jvectormap/jquery-jvectormap.js (add .vectorMap as a JQuery plugin $.fn.vectorMap and registers 'addMap' or 'set' callbacks, for a later world map registration/update: e.g 'world_mill'), useful on Ajax requests when map data is loaded after.
- jvectormap-maps/jquery-jvectormap-world-mill.js
If using bower (bower.json), these were the packages:
"jvectormap": "2.0.5",
"jvectormap-maps": "*"
Best, using jquery.jvectormap.min.js file from distribution.
Or, run locally: 'build.sh', from downloaded .zip file.
See: build.sh