Created
August 4, 2013 23:38
-
-
Save oliyoung/6152508 to your computer and use it in GitHub Desktop.
This (+ d3.js) is magic.
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
$('svg').each(function() { | |
var XMLS = new XMLSerializer(); | |
var content = XMLS.serializeToString(this).trim(); | |
var parent = $(this).parent(); | |
var canvas = $('<canvas style="width: 400px; height: 200px;"/>')[0]; | |
parent.append(canvas); | |
canvg(canvas, content); | |
var theImage = canvas.toDataURL('image/png'); | |
$('svg, canvas', parent).hide(); | |
parent.append("<a href='"+theImage+"' download='chart.png'><img src='"+theImage+"' /></a>"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment