Last active
August 29, 2015 13:56
-
-
Save keighty/9327604 to your computer and use it in GitHub Desktop.
Scaling D3
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> | |
<meta charset="utf-8"> | |
<head> | |
<style> | |
body{margin:0px;} | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: black; | |
shape-rendering: crispEdges; | |
} | |
.axis text { | |
font-family: sans-serif; | |
font-size: 11px; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="http://mbostock.github.com/d3/d3.v2.min.js"></script> | |
<script> | |
var width = 500, | |
height = 500, | |
margin = 50; | |
/*********************** | |
Create Scales | |
***********************/ | |
var scaleX=d3.scale.linear().domain([0,10]).range([margin,width-margin]); | |
var scaleY=d3.scale.linear().domain([0,10]).range([height-margin,margin]); | |
var svg=d3.select("body").append("svg") | |
.attr("width",width) | |
.attr("height",height); | |
var xAxis = d3.svg.axis() | |
.scale(scaleX) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(scaleY) | |
.orient("left"); | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (height - margin) + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(" + margin + ",0)") | |
.call(yAxis); | |
d3.csv("test_data.csv",function(csv) { | |
svg.selectAll("circle").data(csv).enter() | |
.append("circle") | |
.attr("cx",getX) | |
.attr("cy",getY) | |
.attr("r", getR) | |
.style("fill", getColor); | |
function getX(d) { return scaleX(d.X); } | |
function getY(d) { return scaleY(d.Y); } | |
function getR(d) { return d.Quantity / 10; } | |
function getColor(d) { return d.Colors; } | |
)} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment