Skip to main content
XAxis
@coinbase/cds-web-visualization@3.4.0-beta.9
A horizontal axis component for CartesianChart. Displays tick marks, labels, gridlines, and supports custom formatting and data domains.
Import
import { XAxis } from '@coinbase/cds-web-visualization'
SourceView source code
Peer dependencies
  • framer-motion: ^10.18.0
Related components
View as Markdown

Basic Example

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

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, 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...

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...

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...

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.