I can add static html code to a Leaflet popup window but can not load a Dygraph chart into a popup window. How does one load dynamic content into a Leaflet popup window? Here is a simple jsfiddle with a graph and map. https://jsfiddle.net/scottgeowork/pybvvo27/1/

  • Did you try using Ajax? here's a nice discussion & example link
    – NettaB
    Commented Jun 20, 2017 at 8:35
  • I'm not sure how the discussion relates to my jsfiddle example, the json file is static content in a text file, the dygraph is dynamic and exists in the current web page. Could you modify the jsfiddle to display the dygraph in the popup? I have tried myself but still have not been able to get it to work.
    – rsy
    Commented Jun 20, 2017 at 19:30
  • Please take a look at jsfiddle.net/1k4ujv94/2
    – NettaB
    Commented Jun 23, 2017 at 22:30

1 Answer 1


In order to update the popup content I've added an on click function, and used the popup.setContent method.

marker.on('click', onMarkerClick );
function onMarkerClick(e) {
   var popup = e.target.getPopup();
   var chart_div = document.getElementById("graphdiv");
   popup.setContent( chart_div );


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.