d3:line

by Richard Hunter

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js"></script>

JavaScript

const line = d3.line()
  .x(x => x)
  .y(y => y);

const svg = d3.select('body')
  .append('svg')
  .attr('width', 500)
  .attr('height', 500)
  .attr('fill', 'red')
  .attr('stroke', 'blue')
  .attr('stroke-width', 4)

const data = [2, 3, 5, 7, 21, 100];

svg.append('path').attr('d', line(data));