Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active August 22, 2016 17:16
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 d3indepth/2bfe90c7603a062644fc14a866c13f79 to your computer and use it in GitHub Desktop.
Save d3indepth/2bfe90c7603a062644fc14a866c13f79 to your computer and use it in GitHub Desktop.
Natural cubic spline
license: gpl-3.0
height: 200
border: no
<!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()
.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