Skip to content

Instantly share code, notes, and snippets.

@Dudemullet
Created April 29, 2012 07:19
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 Dudemullet/2539441 to your computer and use it in GitHub Desktop.
Save Dudemullet/2539441 to your computer and use it in GitHub Desktop.
basic d3 example
<html>
<head>
<title>Simple D3 demo</title>
</head>
<body>
<div id="myDiv">
</div>
<script type="text/javascript" src="https://raw.github.com/mbostock/d3/master/d3.v2.js"></script>
<script type="text/javascript">
var myJSON =[
{x:25,y:25},
{x:75,y:75},
{x:150,y:150}
];
(function(){
var svg = d3.select("#myDiv")
.append("svg:svg")
.attr("width",200)
.attr("height",200);
var x = d3.scale.linear().domain([0,150]).range([20,150]);
var y = d3.scale.linear().domain([0,150]).range([20,150].reverse());
svg.selectAll("circle")
.data(myJSON)
.enter()
.append("circle")
.attr("class","someCircle")
.attr("cx", function(d){return x(d.x)})
.attr("cy", function(d){return y(d.y)})
.attr("r",5)
.attr("fill","red");
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment