1

I'm having weird problems with updateCloropleth function. I followed this example :

https://github.com/markmarkoh/datamaps/releases/tag/v0.2.2

Here is an example of my problem. When I do this:

map.updateChoropleth({
    "AFG": colorx
});

The color updates. However, when I do this:

var countryx = "AFG";
map.updateChoropleth({
    countryx: colorx
});

It doesn't work.

I've checked that countryx == "AFG" returns true, so it's definitely the same value. The variable colorx can be passed fine, but passing the variable countryx as a key seems to break the function.

Any ideas how or why this is happening?

Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
ConorSheehan1
  • 1,640
  • 1
  • 18
  • 30

1 Answers1

1

You can try this:

var colorx = 100;
var countryx = "AFG";
var countryColor = {};

countryColor["AFG"] = colorx;

map.updateChoropleth(countryColor);

See this thread - basically your problem stems from the fact that these two statements are the same:

var obj = {"countryx": colorx}
var obj = {countryx: colorx}
Community
  • 1
  • 1
Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56