Exploring SVG paths—loads random 108 points. Based on Dashing D3.js screencast
Last active
August 29, 2015 13:57
-
-
Save eesur/9649598 to your computer and use it in GitHub Desktop.
d3 | random SVG paths
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> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
view on bl.ocks.org