1

I am struggling to download my sankey diagram built with google charts as a png/jpg with the clickButton. I have deeply screened other Q&A and tried with purposed examples but I did not get anything working. Can anyone suggest me how to proceed?

I attach the classic sankey version I am using to depict my diagram.

Thanks to help me.

<html>
<body>
<div id="sankey_basic" style="width: 900px; height: 300px;"></div>
<script type="text/javascript"src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
  google.charts.load('current', {'packages':['sankey']});
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'From');
    data.addColumn('string', 'To');
    data.addColumn('number', 'Weight');
    data.addRows([
      [ 'A', 'X', 5 ],
      [ 'A', 'Y', 7 ],
      [ 'A', 'Z', 6 ],
      [ 'B', 'X', 2 ],
      [ 'B', 'Y', 9 ],
      [ 'B', 'Z', 4 ]
    ]);

    // Sets chart options.
    var options = {
      width: 600,
    };

    var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
    chart.draw(data, options);
   }
</script>
</body>
</html>
S.Ghioz
  • 11
  • 1
  • unlike other charts in the google library, sankey diagrams do not have a method for `getImageURI` -- you'll need to use a library such as `html2canvas` -- [here is an example](http://stackoverflow.com/a/10525705/5090771) – WhiteHat Oct 04 '16 at 15:56
  • Thanks a lot! I would try that way. Actually keeping screening the web I found this interesting page [cloudformatter](http://www.cloudformatter.com/GoogleCharts.GoogleChartSamples.GoogleSankeyCharts#) which should allow you to generate the pdf and embed the chart as a png and consequently download it. Nevertheless the code is in part reported, I cannot make it working 'cause I do not know how to integrate it with the main structure :( – S.Ghioz Oct 06 '16 at 06:12

0 Answers0