Adding a highchart to a Leaflet Popup
<p>I'm currently working on a project where the map I create displays all communities the akdatagateway tracks and when a marker is clicked a popup opens displaying a highchart of the population over time char along with some other data. I've gotten all markers to display and was able to get the desired data through the website's API. The problem lies in the generating the highchart in the popup. I cant figure out how to pass in or get the array to the onPopupOpen() to make the subsequent function calls.</p>

<p><strong><em>Reverent Functions:</em></strong></p>

<pre><code>  function addMarker(array){
            for (i in array){
                var communityData = array[i] 
                L.marker([array[i].latitude,array[i].longitude], {bounceOnAdd: true, bounceOnAddOptions: {duration: 250, height: 50}}).addTo(map).on('popupopen', onPopUpOpen)
                .bindPopup('&lt;p style="font-size:130%;"&gt;&lt;b&gt;'+ array[i].name +'&lt;/b&gt;&lt;/p&gt;&lt;div id="container" style="min-width: 300px; height: 200px; margin: 0 auto"&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;PCE for Electricity: ' + pcePrice + '&lt;br /&gt;EIA for Electricity: ' + eiaPrice + '&lt;/p&gt;').addTo(community);
            }
        }

  function getPopulationData(array){
        var id = array.id
        var years = ""
        var populations = ""
        var populationData = []

        var community_pop = $.ajax({type: "GET", url: "/api/models/population/?community=" + id  +"", async: false}).responseText
        community_pop = JSON.parse(community_pop)
        community_pop = community_pop.results
        for ( i = 0; i &lt; community_pop.length; i++){
            years += "'" + community_pop[i].year + "',";
            populations += community_pop[i].total_population +",";
        }
        populationData[0] = years
        populationData[1] = populations
        return populationData;
    }

    function onPopUpOpen (e) {
        //some code to get the community id from popup to use the function.
        // getPopulationData()
        $('#container').highcharts({
        chart: {
            type: 'line'
        },
        title: {
          text: 'Population Over Time'
        },
        subtitle: {
          text: 'Source: AEDG'
        },
        xAxis: {
          categories: [popData[0]]
        },
        yAxis: {
          title: {
            text: 'Population'
          }
        },
        plotOptions: {
          line: {
            dataLabels: {
              enabled: false
            },
            enableMouseTracking: true
          }
        },
        series: [{
          name: '',
          data: [popData[1]]
        }]
      });
    }
</code></pre>

<p>I've tested the functions on elements of the Community array and they do produce the correct data I just can't figure out how to make call them on the pop up and thus generate the highchart. Any commentary is appreciated!</p>

<p><strong><em>Links to Reference info:</em></strong><br>
<a href="http://leafletjs.com/reference.html" rel="nofollow">http://leafletjs.com/reference.html</a><br>
<a href="http://www.highcharts.com/docs" rel="nofollow">http://www.highcharts.com/docs</a>   </p>