axisTop() is a D3 axis generator that creates an axis positioned above its associated scale. It belongs to the d3-axis module. section 4.1.2
Use axisTop() by following the standard D3 axis workflow:
- Pass a scale to the generator so it can distribute values along the axis. section 4.1.2
- Append a group to the chart selection and call the generator on that group. section 4.1.2
- Position the group within the chart layout, using margins when the surrounding chart needs reserved space. section 4.5
Top axis in a chart
In a temperature line chart, pair axisTop() with the scale that distributes the chart’s values, append the axis to an SVG group, and call the generator there. The generated output includes an axis line, ticks, and labels. 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]);
Review a scale definition before supplying it to an axis generator. section 4.1.2
