3

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 Jun 20 '17 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 Jun 20 '17 at 19:30
  • Please take a look at jsfiddle.net/1k4ujv94/2 – NettaB Jun 23 '17 at 22:30
2

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 );
}

https://jsfiddle.net/1k4ujv94/2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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