Public
Edited
Nov 8, 2023
Fork of axis.ticks
Insert cell
Insert cell
Insert cell
axis(d3.scaleLinear())
.ticks(2)
.render()
Insert cell
axis(d3.scaleLinear())
.ticks(5)
.render()
Insert cell
axis(d3.scaleLinear())
.ticks(10)
.render()
Insert cell
Insert cell
axis(d3.scaleLinear())
.ticks(10, "+f") // Implicit precision of one.
.render()
Insert cell
axis(d3.scaleLinear())
.ticks(15, "+f") // Implicit precision of two.
.render()
Insert cell
axis(d3.scaleLinear())
.ticks(10, "$.2f") // Explicit precision of two.
.render()
Insert cell
Insert cell
axis(d3.scaleLinear())
.tickFormat(x => `(${x.toFixed(1)})`)
.render()
Insert cell
Insert cell
axis(d3.scaleLog().domain([1e0, 1e6]))
.ticks(2)
.render()
Insert cell
axis(d3.scaleLog().domain([1e0, 1e6]))
.ticks(5)
.render()
Insert cell
axis(d3.scaleLog().domain([1e0, 1e6]))
.ticks(10)
.render()
Insert cell
Insert cell
axis(d3.scaleLog().base(2).domain([1e0, 1e6]))
.ticks(5)
.render()
Insert cell
axis(d3.scaleLog().base(2).domain([1e0, 1e6]))
.ticks(10)
.render()
Insert cell
axis(d3.scaleLog().base(2).domain([1e0, 1e6]))
.ticks(20)
.render()
Insert cell
Insert cell
axis(d3.scaleLog().domain([1e0, 1e6]))
.ticks(10, "~s")
.render()
Insert cell
axis(d3.scaleLog().domain([1e0, 1e6]))
.ticks(10, formatPower)
.render()
Insert cell
function formatPower(x) {
const e = Math.log10(x);
if (e !== Math.floor(e)) return; // Ignore non-exact power of ten.
return `10${(e + "").replace(/./g, c => "⁰¹²³⁴⁵⁶⁷⁸⁹"[c] || "⁻")}`;
}
Insert cell
Insert cell
axis(d3.scaleTime())
.ticks(5)
.render()
Insert cell
axis(d3.scaleTime())
.ticks(10)
.render()
Insert cell
axis(d3.scaleTime())
.ticks(20)
.render()
Insert cell
Insert cell
axis(d3.scaleTime())
.ticks(d3.timeHour)
.render()
Insert cell
Insert cell
axis(d3.scaleTime())
.ticks(d3.timeHour.every(3))
.render()
Insert cell
Insert cell
axis(d3.scaleTime())
.ticks(d3.timeHour.every(3), "%I %p")
.render()
Insert cell
Insert cell
axis(d3.scalePoint().domain([..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"]))
.tickValues([..."AEIOUY"])
.render()
Insert cell
Insert cell
axis(d3.scalePoint().domain([..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"]))
.tickFormat(x => /[AEIOUY]/.test(x) ? x : "")
.render()
Insert cell
Insert cell
function axis(scale) {
return Object.assign(d3.axisBottom(scale.range([20, width - 20])), {
render() {
return d3.create("svg")
.attr("viewBox", [0, -10, width, 33])
.call(this)
.node();
}
});
}
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