Published
Edited
Dec 11, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
xScale = d3.scaleBand().padding(0.2)
.domain(data.map((d) => d.month))
.range([0, width])
Insert cell
yScale = d3.scaleLinear()
.domain([0, d3.max(data, (d) => d.days)]).nice()
.range([height, 0])
Insert cell
xAxis = (label) => (g) => g
.attr('transform', `translate(${margin.left},${margin.top + height})`)
.call(d3.axisBottom(xScale))
// Add label
.append('text')
.style('text-anchor', 'middle')
.style('fill', '#000')
.style('font-size', '14px')
.text(label)
.attr('x', width / 2)
.attr('y', 50) // Relative to the x axis.
Insert cell
yAxis = (label) => (g) => g
.attr('transform', `translate(${margin.left},${margin.top})`)
.call(d3.axisLeft(yScale))
// Add label
.append('text')
.style('text-anchor', 'middle')
.style('fill', '#000')
.style('font-size', '14px')
.text(label)
.attr('transform', 'rotate(-90)')
.attr('x', -height / 2)
.attr('y', -40) // Relative to the y axis.
Insert cell
Insert cell
Insert cell
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