Created
August 6, 2014 03:01
-
-
Save marcdhansen/3cd848eb6bdca73149d1 to your computer and use it in GitHub Desktop.
D3 in a div
This file contains 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
<!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