Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
114 lines (97 sloc) 2.05 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> March 31 - Example version 1</Title>
<script type="text/javascript" src="http://testingthenews.com/LearningD3/d3/d3.v2.js"></script>
<style type="text/css">
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<script type="text/javascript">
var dataset = [
[20, 2.5],
[62, 1.9],
[1, 1.7],
[41, 0.7],
[2, 0.6],
[2, 0.5],
[0, 0.5],
[48, 0.5],
[1, 0.4],
[8, 0.4],
[15, 0.4],
[6, 0.4],
[6, 0.4],
[3, 0.4],
[2, 0.3],
[6, 0.3],
[11, 0.3],
[7, 0.3],
[8, 0.3],
[4, 0.3],
[2, 0.3],
[2, 0.2],
[15, 0.2],
[5, 0.2],
[5, 0.2],
];
var w = 700;
var h = 500;
var padding = 30;
var xScale = d3.scale.linear()
.domain([0, d3.max(
dataset, function(d){
return d[0];
})])
.range([padding, w - padding]);
var yScale = d3.scale.linear()
.domain([0, d3.max(
dataset, function(d){
return d[1];
})])
.range([h - padding, padding]);
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(5);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(5);
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d){
return xScale(d[0]);
})
.attr("cy", function(d) {
return yScale(d[1]);
})
.attr("r", 5);
svg.append("g")
.attr("transform", "translate(0," + (h - padding) + ")")
.attr("class", "axis")
.call(xAxis);
svg.append("g")
.attr("transform", "translate(" + padding + ", 0)")
.attr("class", "axis")
.call(yAxis);
</script>
</body>
</html>