Published
Edited
Dec 31, 2019
4 forks
5 stars
Insert cell
Insert cell
{
const svg = d3.create('svg').attr('viewBox', [0, 0, width, 200]);

const curve = d3.line().curve(d3.curveNatural);
// N.B. There are several pre-defined functions for curve interpolation in D3; curveNatural is one.
// It's also possible to define your own curve.
// See https://github.com/d3/d3-shape/blob/master/README.md#curves

const points = [[100, 60], [40, 90], [200, 80], [300, 150]];

svg
.append('path')
.attr('d', curve(points))
.attr('stroke', 'black')
// with multiple points defined, if you leave out fill:none,
// the overlapping space defined by the points is filled with
// the default value of 'black'
.attr('fill', 'none');

return svg.node();
}
Insert cell
d3 = require('d3')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more