Interacting between JavaScript Maps and JavaScript Charts

Martynas Majeris -

Say, you have a map on your page. Perfect.

Now you want to add a little chart. Easy.

Finally you want the chart to go over the map, and, to further complicate things, want the chart to update it's data when user clicks particular countries on the map.

It may be easier than you think.

Placing the chart over the map is as simple as positioning <div> element over each other:

<div style="width: 100%; height: 362px; position: relative;">
 <div id="chartdiv" style="width: 200px; height: 150px; position: absolute; bottom: 0; right: 0; z-index: 100;"></div>
 <div id="mapdiv" style="width: 100%; height: 362px; position: absolute; top: 0; left: 0;"></div>


Now, in order to catch clicks on the countries we will use a handler for "clickMapObject" event, which will update chart's dataProvider property as well as set the appropriate label.

map.addListener("clickMapObject", function (event) {
 if ( != undefined && chartData[] != undefined) {
   chart.dataProvider = chartData[];
   chart.addLabel("0", "!20", event.mapObject.title, "center", 16);


And here's a working demo:

Have more questions? Submit a request


  • Avatar
    Maria Samuel

    Upon clicking the map was not getting updated. The fiddle was missing selectable: true in the area settings. 

  • Avatar

    hi Martynas

    I wanted to display data in a <div> when the user clicks on a map object. as in when user clicks on the country Australia the div needs to be displayed under the map <div>.

    <div id='mapdiv'></div>

    <div id='mapdata'></div>

    is this possible? appreciate your support in this regard


  • Avatar

    The map is not rendering now.

Powered by Zendesk