Demonstration of SVG line generator from D3 in Depth book by Peter Cook.
-
-
Save openhubdev/dbf249209528518e7530e057d466515c to your computer and use it in GitHub Desktop.
D3 line generator
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
license: gpl-3.0 | |
height: 120 | |
border: no |
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> | |
<meta charset="utf-8"> | |
<head> | |
<title>SVG Line Generator</title> | |
</head> | |
<style> | |
path { | |
fill: none; | |
stroke: #aaa; | |
} | |
</style> | |
<body> | |
<svg width="600" height="100"> | |
<path transform="translate(200, 0)" /> | |
</svg> | |
<script src="//d3js.org/d3.v4.min.js"></script> | |
<script> | |
var data = [[0, 50], [100, 80], [200, 40], [300, 60], [400, 30]]; | |
//var lineGenerator = d3.line(); | |
var lineGenerator = d3.line() | |
.curve(d3.curveNatural); | |
var pathString = lineGenerator(data); | |
d3.select('path') | |
.attr('d', pathString); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment