title: Trying to load a google chart through a click event - get the error: Uncaught Error: Map container not found
body: <p>I am trying to load a google chart through a jquery ajax call by clicking on a geojson layer, which is loaded over a map. I'm using the leaflet API for the map creation and for its layers and the google charts API for creating the chart. When I'm trying to load the page, it won't finish loading and it gives me the following error: <strong>Uncaught Error: Map container not found</strong>.</p>
  
  <p>When I click on the error in the console, it takes me to the leaflet library where this part is marked as an error: ".get(t);if(!e)throw new Error("Map container not found.");if(e._leaflet)throw new Error("Map container is already initialized.");e._leaflet=!0},_initLayout:function(){var t=this._container;o.DomUtil.addClass(t,"leaflet-container"+(o.Browser.touch?" leaflet-t..."</p>
  
  <p>When I'm commenting out the code for the chart, the page loads with the map without a problem.</p>
  
  <p>I'm using these js libraries for the chart and the map:</p>
  
  <pre><code>&lt;script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>My code for the chart, the geojson and the map is as follows:</p>
  
  <pre><code>function drawChart() {                                    
  
       var jsonData = $.ajax({
              url: "http://climatedataapi.worldbank.org/climateweb/rest/v1/country/cru/tas/year/" + feature.properties.ISO3.jsonp,
              data: {page: 1, format: "jsonp", prefix: "getdata"},
              crossDomain: true,
              jsonpCallback: "getdata",
          }).done(function (results) {
              var data = new google.visualization.DataTable();
              data.addColumn('datetime', 'Year');
              data.addColumn('number', 'Temp');
              $.each(results, function (i, row) {
                  data.addRow([
                      (new Date(row.year)),
                      parseFloat(row.data),
                  ]);
              });
              var chart = new google.visualization.LineChart(document.getElementById("container"));                                
              chart.draw(data, {
                      title: 'Annual Average Temperature'
                  });                       
              })//end function
  }//end drawChart                          
  
  google.load('visualization', '1', {
         packages: ['corechart']
  });  
  
  var aLayerThree = L.geoJson(aGeoJson, {
          style: function (feature) {
              return {stroke: true, color: "#3333ff", weight: 2, fillOpacity: 0};
          },
          onEachFeature: function (feature, layer) {
  
                  layer.on('mouseover', function() {
                          layer.setStyle({fillColor: "#4da6ff", fillOpacity: 0.4});
                          aDiv.innerHTML = feature.properties.NAME;
  
                  layer.on('mouseout', function() {
                          layer.setStyle({ fillOpacity: 0});
                          aDiv.innerHTML = "Web-Mapping Techniques";
  
                  $('layer').on('click', function() {       
                           drawChart();
  
                   })// end click
                  })// end mouseout
                  })//end mousover
          } // end onEachFeature
  });// end GeoJson            
  
  //Create our Map Object
  map = L.map('myMap', {
                  fullscreenControl: true,
              center: centerlatlng,
              minZoom: 2,
              zoom:   4,
              layers: [aLayerOne, aLayerThree]
  });
  </code></pre>
  
  <p>My html looks like that:</p>
  
  <pre><code>&lt;body&gt;
  &lt;div class="container-fluid"&gt;       
      &lt;div class="row"&gt;
          &lt;!--&lt;br /&gt;--&gt;
      &lt;/div&gt;&lt;!-- Row 1 --&gt;        
      &lt;div class="row"&gt;
          &lt;nav class="col-lg-10 col-lg-offset-1 navbar navbar-default" role="navigation"&gt;            
              &lt;a class="navbar-brand" href="#"&gt;Annual Temperature and Precipitation by Country&lt;/a&gt;
              &lt;ul class="nav navbar-nav pull-right"&gt;
                  &lt;li class="active"&gt;&lt;a href="#" id="anInfo"&gt;Info&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#" id="anAbout"&gt;About&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;                           
          &lt;/nav&gt;
      &lt;/div&gt;&lt;!-- Row 2 --&gt;        
      &lt;div class="row"&gt;           
          &lt;div id="myMap" class="col-lg-10 col-lg-offset-1"&gt;&lt;/div&gt;
      &lt;/div&gt;&lt;!-- Row 3 --&gt;        
      &lt;div class="row"&gt;
          &lt;br/&gt;
      &lt;/div&gt;&lt;!-- Row 4 --&gt;        
      &lt;div class="row"&gt;
          &lt;div id="container" style="width:100%; height:400px;"&gt;&lt;/div&gt;            
      &lt;/div&gt;&lt;!-- Row 5 --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am a newbie in creating charts. What am I doing wrong?
  Thanks in advance!</p>