I need my DG-created SVG graphics to load. I found one answer to this question that suggested base64 SVG XML encoding, but then I found this post which says plain text should be fine too, so I came up with something like this:
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<script>
var data = [22, 33, 11, 55, 44];
var svg = d3.select('body').append('svg')
.attr('id', 'chart')
.attr('version', '1.1')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.attr('width', 600)
.attr('height', 400)
.style('background-color', 'powderblue')
.selectAll('circle')
.data(data)
.enter().append('circle')
.attr('cx', function(d) { return 8*d; })
.attr('cy', function(d) { return 4*d; })
.attr('r', function(d) { return d; })
.style('fill', function(d) { return d3.rgb(2*d, 4*d, 3*d); })
;
d3.select('body').append('a')
.attr('href-lang', 'image/svg+xml')
.attr('href', 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg">' + unescape(svg.node().parentNode.innerHTML) + '</svg>')
.text('Download')
;
</script>
</body>
</html>
, , , ( , , bg) , SVG HTML-. SVG, D3? svg.html() d3.select(svg).html(), null.