Search code examples
mapsselectedamcharts

Value of selected country amcharts


When I select country on map, how can I get a value of this country and pass it to variable? Thanks a lot! I used amcharts.com Or it can be another solution? I you know how to choose country on map, i'll be very grateful!


Solution

  • You can use "clickMapObject" event to catch all the information about clicked object. I.e.:

    map.addListener("clickMapObject", function (event) {
        alert( 'Clicked ID: ' + event.mapObject.id + ' (' + event.mapObject.title + ')' );
    });
    

    Here's a working example:

    http://jsfiddle.net/amcharts/k67gB/light/

    Please note that in order for this event to fire the country needs to be clickable. This means that either "autoZoom" needs to be enabled or all areas need to be set as "selectable":

    var map = AmCharts.makeChart("mapdiv",{
      ...
      "areasSettings": {
        "autoZoom": true
      }
    });
    

    Or

    var map = AmCharts.makeChart("mapdiv",{
      ...
      "areasSettings": {
        "selectable": true
      }
    });