Skip to content

Instantly share code, notes, and snippets.

@ZJONSSON
Created January 11, 2012 18:32
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 ZJONSSON/1596053 to your computer and use it in GitHub Desktop.
Save ZJONSSON/1596053 to your computer and use it in GitHub Desktop.
Internalizing chart variables (mod)
<html>
<head><script type="text/javascript" src="https://raw.github.com/gist/1595803/d3mod.js"></script></head>
<body>
<script type="text/javascript">
d3.select("body")
.append("svg:svg")
.property("__chart__",function() {
return {
X:d3.scale.linear()
.domain([50,60])
.range([0,this.parentNode.offsetWidth]),
Y:d3.scale.linear()
.domain([1,100])
.range([this.parentNode.offsetHeight,0])
}
})
.selectAll(".series")
.data([{x:51,y:23},{x:55,y:55},{x:52,y:83}])
.enter()
.append("svg:circle")
.attr("cx",function(d) { return this.__chart__.X(d.x)})
.attr("cy",function(d) { return this.__chart__.Y(d.y)})
.attr("r",10)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment