Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active May 29, 2020 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save d3indepth/90851f3bd602f17a7f32691819e2ed2e to your computer and use it in GitHub Desktop.
Save d3indepth/90851f3bd602f17a7f32691819e2ed2e to your computer and use it in GitHub Desktop.
Line generator (render to canvas)
license: gpl-3.0
height: 160
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Line generator (render to canvas element)</title>
</head>
<style>
</style>
<body>
<canvas width="600" height="150"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var context = d3.select('canvas').node().getContext('2d');
var lineGenerator = d3.line()
.context(context);
var points = [
[0, 80],
[100, 100],
[200, 30],
[300, 50],
[400, 40],
[500, 80]
];
context.strokeStyle = '#999';
context.beginPath();
lineGenerator(points);
context.stroke();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment