Skip to content

Instantly share code, notes, and snippets.

@emi-lp
Created September 30, 2015 00:55
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 emi-lp/130ed614d825490c23d8 to your computer and use it in GitHub Desktop.
Save emi-lp/130ed614d825490c23d8 to your computer and use it in GitHub Desktop.
Test__01
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width: 100%; height: 100%; }
</style>
</head>
<body>
<script>
var margin = {top: 20, right: 10, bottom: 20, left: 10};
var width = 960 - margin.left - margin.right;
var height = 500 - margin.top - margin.bottom;
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var jsonCircles = [
{ "x_axis": 30, "y_axis": 30, "radius": 20, "color" : "green" },
{ "x_axis": 70, "y_axis": 70, "radius": 20, "color" : "purple"},
{ "x_axis": 195, "y_axis": 188, "radius": 20, "color" : "purple"},
{ "x_axis": 242, "y_axis": 218, "radius": 20, "color" : "orange"},
{ "x_axis": 142, "y_axis": 212, "radius": 20, "color" : "purple"},
{ "x_axis": 110, "y_axis": 100, "radius": 20, "color" : "red"}];
var circles = svg.selectAll("circle")
.data(jsonCircles)
.enter()
.append("circle");
var rects = svg.selectAll("rect")
.data(jsonCircles)
.enter()
.append("rect");
var circleAttributes = circles
.attr("cx", function (d) { return d.x_axis; })
.attr("cy", function (d) { return d.y_axis; })
.attr("r", function (d) { return d.radius; })
.style("fill", function(d) { return d.color; });
var rectAttributes = rects
.attr("x", function (d) { return d.x_axis; })
.attr("y", function (d) { return d.y_axis; })
.attr("width", function (d) { return d.radius; })
.attr("height", function (d) { return d.radius; })
.style("fill", function(d) { return d.color; });
</script>
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment