Skip to main content
XAxis
@coinbase/cds-web@9.28.0
A horizontal axis component for CartesianChart. Displays tick marks, labels, gridlines, and supports custom formatting and data domains.
import { XAxis } from '@coinbase/cds-web/visualizations/chart'
Peer dependencies
  • framer-motion: ^10.18.0
Related components

Basics​

The XAxis component provides a horizontal axis for charts with automatic tick generation and labeling.

Loading...

Multiple X Axes (Horizontal Layout)​

When layout="horizontal", you can configure multiple x-axes and bind each series to an axis with xAxisId. Use XAxis's axisId prop to render each axis configuration.

Loading...

Axis Config​

Properties related to the scale of an axis are set on the Chart component. This includes scaleType, domain, domainLimit, range, data, and categoryPadding.

Scale Type​

XAxis supports linear (default), log, and band scale types. linear and log are numeric scales while band is a categorical scale. band scale is required for bar charts.

Loading...

Domain​

An axis's domain is the range of values that the axis will display. You can pass in either an object (AxisBounds) with min and max properties (both optional), or a function that receives initial AxisBounds and returns an adjusted AxisBounds.

Loading...

Domain Limit​

For numeric scales, you can set the domain limit to nice or strict (default for XAxis). nice will round the domain to human-friendly values, while strict will use the exact min/max values from the data. See d3-scale for more details.

Range​

An axis's range is the range of values that the axis will display in pixels. This is most useful for adjusting the sizing of the data inside of the chart's drawing area.

You can pass in either an object (AxisBounds) with min and max properties (both optional), or a function that receives initial AxisBounds and returns an adjusted AxisBounds.

Loading...

Data​

Data sets x values for the axis.

String Data​

Using string data will allow you to set string x values for each data point.

Loading...

Number Data​

Using number data with a numeric scale will allow you to adjust the x values for each data point.

Loading...

Category Padding​

For band scales, you can set the category padding to adjust the spacing between categories. The default is 0.1. This is a value between 0 and 1, where 0.1 = 10% spacing.

Loading...

Axis Props​

Properties related to the visual appearance of the XAxis are set on the component itself. This includes position, showGrid, showLine, showTickMarks, size, tickInterval, ticks, tickLabelFormatter, tickLabelOverflow, and tickMarkSize.

Position​

You can set the position of an axis to top or bottom (default).

Loading...

Grid​

You can show grid lines at each tick position using the showGrid prop.

Loading...

You can also customize the grid lines using the GridLineComponent prop.

Loading...

On band scales, you can also use bandGridLinePlacement to control where grid lines appear relative to each band.

Using edges will place a grid line at the start of each band, plus a grid line at the end of the last band.

Loading...

Line​

You can show the axis line using the showLine prop.

Loading...

You can also customize the axis line using the classNames and styles props.

Loading...

Size​

The size prop sets the size of the axis in pixels. The default is 32 for XAxis, but can be adjusted to fit the size of your data.

Loading...

Ticks​

You can use the ticks, requestedTickCount, and tickInterval (default for XAxis) props to control the number and placement of ticks on the XAxis.

ticks accepts an array of numbers, which corresponds to the values of that axis that you would like to display ticks for.

Loading...

Using requestedTickCount will use D3's ticks function to determine the number and placement of ticks. Note that this count is not guaranteed to be respected.

Loading...

tickInterval, which accepts a number for the gap between ticks in pixels, will measure the available space and try to create evenly spaced ticks. It will always include the first and last values of the domain.

Loading...

Tick Marks​

You can show tick marks on the axis using the showTickMarks prop. You can also customize the tick mark size using the tickMarkSize prop.

Loading...

On band scales, you can also use bandTickMarkPlacement to control where tick marks appear relative to each band.

Using edges will place a tick mark at the start of each band, plus a tick mark at the end of the last band.

Loading...

Tick Labels​

You can customize the tick labels using the tickLabelFormatter prop. It will receive the x data value of the tick. Meaning, if data is provided for the axis, it will receive the string label for the tick.

Loading...

If no data is set for the axis, it will receive the regular number value of the tick, which is normally the index corresponding to each value in the series.

Loading...

Tick Label Overflow​

Use tickLabelOverflow to control how tick labels behave at the chart edges.

Loading...

Label​

You can add a label to the axis using the label prop.

Loading...

Custom Tick Labels​

You can create custom tick label components using the TickLabelComponent prop for advanced styling that works cross-platform.

Loading...

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.