Public
Edited
Oct 24, 2023
10 forks
39 stars
Insert cell
Insert cell
Insert cell
d3.scaleLinear()
.ticks()
Insert cell
Insert cell
Insert cell
Insert cell
d3.scaleLinear()
.domain([-100, 100])
.ticks(50)
Insert cell
Insert cell
Insert cell
extent = [1.03, 95.4]
Insert cell
notNiceScale = d3.scaleLinear().domain(extent)
Insert cell
notNiceScale.domain()
Insert cell
notNiceScale.ticks() // missing 0 and 100 👎
Insert cell
Insert cell
niceScale = d3.scaleLinear().domain(extent).nice()
Insert cell
niceScale.domain()
Insert cell
niceScale.ticks() // 👍
Insert cell
Insert cell
Insert cell
d3.scaleLog()
.domain([1, 1000])
.ticks()
Insert cell
Insert cell
Insert cell
unitScale = d3.scaleLinear().domain([0, 1])
Insert cell
format10 = unitScale.tickFormat(10)
Insert cell
format100 = unitScale.tickFormat(100)
Insert cell
unitScale.ticks(10).map(format10) // one decimal
Insert cell
unitScale.ticks(100).map(format100) // two decimals
Insert cell
Insert cell
logScale = d3.scaleLog().domain([1, 1000])
Insert cell
logFormat10 = logScale.tickFormat(10)
Insert cell
logScale.ticks(10).map(logFormat10)
Insert cell
Insert cell
Insert cell
logFormat10alt = logScale.tickFormat(10, "")
Insert cell
logScale.ticks(10).map(logFormat10alt)
Insert cell
Insert cell
Insert cell
timeScale = d3.scaleUtc()
Insert cell
timeScale.ticks(10)
Insert cell
timeScale.ticks(10).map(timeScale.tickFormat())
Insert cell
Insert cell
Insert cell
timeFormat = d3.utcFormat("%I %p")
Insert cell
timeScale.ticks(10).map(timeFormat)
Insert cell
Insert cell
Insert cell
timeScale.ticks(d3.utcHour) // every hour
Insert cell
timeScale.ticks(d3.utcMinute.every(15)) // every 15 minutes
Insert cell
Insert cell
Insert cell
tickCount = width / 80
Insert cell
unitScale.ticks(tickCount)
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