Published
Edited
Sep 14, 2020
2 forks
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const height = 100;
const xValue = d => d.x;
const yValue = d => d.y;

const xScale = d3
.scaleLinear()
.domain(d3.extent(data.map(xValue)))
.range([0, width]);

const yScale = d3
.scaleLinear()
.domain([-1, 1])
.range([0, height]);

const svg = d3.create('svg').attr('viewBox', `0 0 ${width} ${height}`);

const line = d3
.line()
.x(d => xScale(xValue(d)))
.y(d => yScale(yValue(d)));

svg
.append('path')
.datum(data)
.attr('d', line)
.attr('stroke', 'steelblue')
.attr('fill', 'none');

return svg.node();
}
Insert cell
curve = Math.sin
Insert cell
Insert cell
Insert cell
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