Skip to content

Instantly share code, notes, and snippets.

@haehn
Created March 2, 2026 15:47
Show Gist options
  • Select an option

  • Save haehn/e3dbdf8000b84046d6de2986c0b62017 to your computer and use it in GitHub Desktop.

Select an option

Save haehn/e3dbdf8000b84046d6de2986c0b62017 to your computer and use it in GitHub Desktop.
D3 Simple Line
<html>
<head>
<script src="https://d3js.org/d3.v7.min.js"></script>
</head>
<body>
<svg id='s' width="600" height="400"></svg>
<script>
// create data
var data = [
{x: 0, y: 20},
{x: 150, y: 150},
{x: 300, y: 100},
{x: 450, y: 20},
{x: 600, y: 130}]
// grab
var svg = d3.select("svg");
// prepare a helper function
var lineFunc = d3.line()
.x( function(d) { return d.x } )
.y( function(d) { return d.y } )
// Add the path using this helper function
svg.append('path')
.attr('d', lineFunc(data))
.attr('stroke', 'black')
.attr('fill', 'none');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment