Skip to content

Instantly share code, notes, and snippets.

@joews
Created June 20, 2014 18:59
Show Gist options
  • Save joews/b07f21f42131cca67e4e to your computer and use it in GitHub Desktop.
Save joews/b07f21f42131cca67e4e to your computer and use it in GitHub Desktop.
d3 gist boilerplate
<!DOCTYPE html>
<html>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var min = 0,
max = 10,
minSeriesLength = 4,
maxSeriesLength = 8;
// Create a one dimensional array of random [x,y] pairs
function getSeries() {
var length = randomInt(minSeriesLength, maxSeriesLength),
series = [];
for(var i = 0; i < length; ++i) {
series.push([randomInt(min, max), randomInt(min, max)]);
}
return series;
}
var margin = 20,
outerWidth = 500,
outerHeight = 500,
width = outerWidth - 2 * margin,
height = outerWidth - 2 * margin;
var svg = d3.select("body").append("svg")
.attr("width", outerWidth)
.attr("height", outerHeight)
.append("g")
.attr("transform", "translate(" + margin + "," + margin + ")");
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment