Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@marcdhansen
Created August 6, 2014 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcdhansen/3cd848eb6bdca73149d1 to your computer and use it in GitHub Desktop.
Save marcdhansen/3cd848eb6bdca73149d1 to your computer and use it in GitHub Desktop.
D3 in a div
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<div id="viz" style="position:absolute;width:100%;height:100%"></div>
<script type="text/javascript">
var div = d3.select("#viz");
var divWidth = parseInt(div.style("width"));
var divHeight = parseInt(div.style("height"));
var svg = d3.select("#viz")
.append("svg")
.attr("width", divWidth)
.attr("height", divHeight);
svg.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", divWidth)
.attr("height", divHeight)
.attr("fill", "burlywood")
;
svg.append("text")
.attr("x", 0)
.attr("y", 20)
.attr("text-anchor", "left")
.style("font-size", "20px")
.text(divWidth + "x" + divHeight);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment