Printing a PNG image of a google Charts

661 views
Skip to first unread message

feyseel

unread,
Dec 13, 2016, 8:59:04 AM12/13/16
to Google Visualization API

Does anyone have some examples of him printing an image of a google chart, the example google gives i can't seem to understand.

https://developers.google.com/chart/interactive/docs/printing

Mohammad Al Khalili

unread,
Dec 14, 2016, 6:08:16 AM12/14/16
to Google Visualization API
Here is one that worked for me :

....... Load the libraries and prepare your data and options


          var chart = new google.visualization.BarChart(document.getElementById('chart_div'));


      google.visualization.events.addListener(chart, 'ready', function () {
        document.getElementById('png').innerHTML = '<img src="' + chart.getImageURI() + '">';
        document.getElementById('png').outerHTML = '<a href="' + chart.getImageURI() + '">Printable version</a>';
      });


          chart.draw(data, options);
          

        
        

      }
    </script>
  </head>

  <body>
    <div id="chart_div"></div>
    <div id='png'></div>
  </body>
Reply all
Reply to author
Forward
0 new messages