Created
January 20, 2015 11:42
-
-
Save matijagrcic/62f53e61a3a7816cff6a to your computer and use it in GitHub Desktop.
Google chart to png using canvg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="#" target="_blank" class="btn btn-info print-chart" data-chart-container="my-chart" data-chart-name="my-chart-name">Save chart</a> | |
| MyApp.saveChart = function saveChart($button) { | |
| var printButton = $button; | |
| var container = printButton.data('chart-container'); | |
| var name = printButton.data('chart-name'); | |
| var chartContainer = $("#" + container); | |
| var chartArea = chartContainer.find('svg').parent(); | |
| var svg = chartArea.html(); | |
| var canvas = document.createElement('canvas'); | |
| canvg(canvas, svg); | |
| var imageUri = canvas.toDataURL("image/png"); | |
| printButton.attr('href', imageUri); | |
| printButton.attr('download', name + '.png'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment