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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more