Published
Edited
Feb 15, 2022
Fork of Simple D3
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Lines(d3.range(columns), {
colour: '#a90636',
x: (d, i) => i * (w / (columns - 1)) + strokeWidth
})
Insert cell
Insert cell
xData = d3.quantize( d3.interpolate(strokeWidth, w), columns )
Insert cell
Lines(xData, {
colour: '#4f8fe6',
x: d => d // use the data for `x` placement
})
Insert cell
Insert cell
Insert cell
Lines(d3.range(columns), {
colour: '#9c52f2',
x: (d, i) => linearScale(i) // could pass in `d` as it's the same as `i` in this case
})
Insert cell
Insert cell
Insert cell
Lines(d3.range(columns), {
colour: '#ffa6d9',
x: (d, i) => pointScale(i)
})
Insert cell
Insert cell
function Lines(data, {
colour = 'hsl(80deg 70% 40%)',
x = null // pass in how to calcualte x
} = {}) {
const svg = d3.create('svg')
.attr('width', width)
.attr('height', height);

svg
.selectAll('line')
.data(data)
.join('line')
.attr('x1', x)
.attr('x2', x)
.attr('y1', 0)
.attr('y2', height)
.attr('stroke-width', strokeWidth)
.attr('stroke', colour)
return svg.node()
}
Insert cell
w = width-(strokeWidth*2)
Insert cell
height = 50
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