Public
Edited
Oct 26, 2023
4 forks
Importers
58 stars
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

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