markmarkoh / datamaps

Customizable SVG map visualizations for the web in a single Javascript file using D3.js
http://datamaps.github.io
MIT License
3.78k stars 1.01k forks source link

Uncaught TypeError: Cannot read property 'offsetWidth' of null #173

Closed MoMaghraby closed 9 years ago

MoMaghraby commented 9 years ago

Whenever i run the code i get this error.

Uncaught TypeError: Cannot read property 'offsetWidth' of null

markmarkoh commented 9 years ago

@StefanKage link to this page where I can see it and help debug?

MoMaghraby commented 9 years ago

Okay i solved the error, now i have a problem. I want to enter an IP address and turn it into a country name then change its color on the map. But i can't enter the country name as a variable.

var interval_1=window.setInterval(function() {

var name = "USA";

map.updateChoropleth({

    name : colors(Math.random() * 10),

}); }, 2000);

markmarkoh commented 9 years ago

To follow up on the original issue - that error is caused when element returns null, for instance if you said:

new Datamap({
element: document.getElementById('not-on-page')
});

If an element with an id of not-on-page is not on the page at the time that code runs, you'll see this error.

MoMaghraby commented 9 years ago

Great ! thanks alot.

nick-brady commented 7 years ago

people trying to use datamaps in react If you're trying to use data maps on a component in react, make sure you create the map (e.g. var map = new Datamap({element: document.getElementById('container')}); inside of the componentDidMount() method. I was running the code to bind the map to an element I thought was on the DOM before it was mounted effectively causing the same issue mark mentioned above.