Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reading SVG files with D3js

d3.text() is the 1st key to include a SVG file on the DOM using D3js, the 2nd one is d3.selection().html(). After you inject the SVG you can manipulate the SVG using common D3js technics.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
d3.text('boom.svg', (textsvg) => {
d3.selectAll("body")
.html(textsvg)
.select("*")
.attr('width', `${width}px`)
.attr('height', `${height}px`);
});
</script>
</body>
</html>
These Pop Art Elements is licensed under Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/.
Under this license, you are free to copy and redistribute the material in any medium or format, remix, transform and build upon the material for any purpose, even commercially. In exchange, you must give appropriate credit to Vecteezy (http://www.vecteezy.com/).
For more free resources, visit http://graphicflip.com/
- Monika Ratan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment