Created
August 18, 2013 19:33
-
-
Save koaning/6263534 to your computer and use it in GitHub Desktop.
football '13
This file contains hidden or 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> | |
<html> | |
<head> | |
<title>The d3 test</title> | |
<style> | |
.chart { | |
} | |
.main text { | |
font: 10px sans-serif; | |
} | |
.axis line, .axis path { | |
shape-rendering: crispEdges; | |
stroke: black; | |
fill: none; | |
} | |
circle { | |
fill: steelblue; | |
} | |
</style> | |
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script> | |
</head> | |
<body> | |
<div class='content'> | |
<!-- /the chart goes here --> | |
</div> | |
<script type="text/javascript" src="scatterchart.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
var data = [[62,22], | |
[27,10], | |
[4.9,12], | |
[35,17], | |
[7.1,19], | |
[18,21], | |
[22.5,9], | |
[8.5,10], | |
[14,10], | |
[11.5,10], | |
[61,22], | |
[8,9], | |
[46,7], | |
[46,11], | |
[30,19], | |
[7.5,6], | |
[8.1,5]]; | |
var margin = {top: 20, right: 15, bottom: 60, left: 60} | |
, width = 800 - margin.left - margin.right | |
, height = 400 - margin.top - margin.bottom; | |
var x = d3.scale.linear() | |
.domain([0, d3.max(data, function(d) { return d[0]; })]) | |
.range([ 0, width ]); | |
var y = d3.scale.linear() | |
.domain([0, d3.max(data, function(d) { return d[1]; })]) | |
.range([ height, 0 ]); | |
var chart = d3.select('body') | |
.append('svg:svg') | |
.attr('width', width + margin.right + margin.left) | |
.attr('height', height + margin.top + margin.bottom) | |
.attr('class', 'chart') | |
var main = chart.append('g') | |
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') | |
.attr('width', width) | |
.attr('height', height) | |
.attr('class', 'main') | |
// draw the x axis | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient('bottom'); | |
main.append('g') | |
.attr('transform', 'translate(0,' + height + ')') | |
.attr('class', 'main axis date') | |
.call(xAxis); | |
// draw the y axis | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient('left'); | |
main.append('g') | |
.attr('transform', 'translate(0,0)') | |
.attr('class', 'main axis date') | |
.call(yAxis); | |
var g = main.append("svg:g"); | |
g.selectAll("scatter-dots") | |
.data(data) | |
.enter().append("svg:circle") | |
.attr("cx", function (d,i) { return x(d[0]); } ) | |
.attr("cy", function (d) { return y(d[1]); } ) | |
.attr("r", 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment