The new Google Chart API creates charts as SVGs (not PNGs as it used to). I’d like to be able to save the generated SVG. How can I do this?
If I use Chrome to inspect elements on the page, I can find the svg tag that holds the SVG. I’d like to be able to get the generated SVG using JavaScript. I’d prefer not to search the HTML source for the svg tag in JavaScript, and if there’s a way to get the SVG string directly from the chart object (maybe the ChartWrapper class?) that would be preferable.
Apparently, this is not supported by the Google Charts API (references 1, 2, and 3). I created the below hack to get the SVG string as a workaround. Below is the full JavaScript.
Note that this doesn’t work in IE because the Google Charts API doesn’t use SVG in IE. I’m always open to better solutions.
(thanks to untill for suggesting
.outerHTMLover.parentNode.innerHTML)