Skip to content

Instantly share code, notes, and snippets.

@eesur
Last active August 29, 2015 13:57
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 eesur/9649598 to your computer and use it in GitHub Desktop.
Save eesur/9649598 to your computer and use it in GitHub Desktop.
d3 | random SVG paths
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>d3.js | SVG paths</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<script>
var w = 960, h = 500;
// dataset = [
// { "x":05, "y":30}, { "x":75, "y":30},
// { "x":75, "y":90}, { "x":150, "y":90},
// { "x":150, "y":150}, { "x":190, "y":150}
// ];
var dataset = [];
for (var i = 0; i < 108; i++) {
var x = Math.floor((Math.random()*900)+1);
var y = Math.floor((Math.random()*500)+1);
dataset.push({"x":x, "y":y});
};
var lineFunction = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("linear");
svgViewport = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
svgViewport.append("path")
.datum(dataset)
.attr("d", lineFunction)
.attr("stroke", "black")
.attr("stroke-width", 3)
.attr("fill", "none");
</script>
</body>
</html>
@eesur
Copy link
Author

eesur commented Mar 19, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment