liveBook · Manning

axisRight()

As explained in D3.js in Action, Third Edition

axisRight() is a D3 axis generator function that creates an axis positioned to the right of its associated scale.

axisRight() is a D3 axis generator that creates the right-side form of an axis from an associated scale. D3 includes it alongside axisTop(), axisBottom(), and axisLeft() in the d3-axis module. section 4.1.2 section 4.5

Use axisRight() as part of the standard D3 axis workflow:

  • Pass the scale responsible for distributing values along the right axis. section 4.1.2 section 4.5
  • Apply the generator to a D3 selection with call() so it constructs the axis line, ticks, and labels. section 4.1.2 section 4.5
  • Position the containing SVG group using chart margins or a transform; generated axes initially appear at the selection’s origin. section 4.1.2 section 4.5

Right-side scale axis

A right-side axis follows the same pattern as the other generators: create it from the relevant scale, append an SVG group, and call the generator on that selection. A linear temperature scale can supply the values, while the group’s placement reserves the chart’s right margin. section 4.1.2 section 4.5

const maxTemp = d3.max(data, d => d.max_temp_F);
const yScale = d3.scaleLinear()
  .domain([0, maxTemp])
  .range([innerHeight, 0]);

Inspect the linear y-scale pattern that supplies values to an axis generator. section 4.1.2

How D3.js in Action, Third Edition covers it

How deep it goes
Explains scale input, SVG output, call(), and positioning, but does not detail right-axis-specific styling.
Examples
Uses temperature scales and line-chart axes to demonstrate scale construction, axis appending, group placement, and label styling.
What it assumes
Assumes basic D3 selections and scales while demonstrating axis construction from those pieces.
What you can do after
Operate/configure it by passing a scale to axisRight() and calling the generator on an SVG selection.
How it connects
Connects axis generators with scales, D3 selections, call(), SVG groups, ticks, labels, and the margin convention.

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.