put Google line chart in Leaflet popup

前端 未结 1 1927
悲哀的现实
悲哀的现实 2021-01-27 01:17

I\'m trying to insert a Google line chart into a standalone Leaflet popup. I have the chart generation code in the header as instructed here, and then I put the div element in t

1条回答
  •  独厮守ぢ
    2021-01-27 02:09

    try structuring the code similar to the following snippet...

    1) load google charts before anything else

    2) then load other stuff you need

    3) then try opening the popup

    // run this before anything else on the page
    google.charts.load('current', {
      callback: initPage,
      packages: ['corechart']
    });
    
    function initPage() {
      // do normal start up stuff here
      // ...
    
      // open the popup
      var popup = L.popup()
        .setLatLng([51.5, -0.09])
        .setContent('
    ') .openOn(mymap); drawChart(); } function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Topping'); data.addColumn('number', 'Slices'); data.addRows([ ['Mushrooms', 3], ['Onions', 1], ['Olives', 1], ['Zucchini', 1], ['Pepperoni', 2] ]); var container = document.getElementById('curve_chart'); var chart = new google.visualization.LineChart(container); chart.draw(data); }

    0 讨论(0)
提交回复
热议问题