Skip to content

Charts - Axis

Axis provides associate values to element positions.

Axes are used in the following charts: <LineChart />, <BarChart />, <ScatterChart />.

Defining axis

Like your data, axis definition plays a central role in the chart rendering. It's responsible for the mapping between your data and element positions.

You can define custom axes by using xAxis and yAxis props. Those props expect an array of objects.

Here is a demonstration with two lines with the same data. But one uses a linear, and the other a log axis.

Each axis definition is identified by its property id. And series specify the axis they use with xAxisKey and yAxisKey properties.

010203040506070809010001020304050607080901001101210201002001k
Press Enter to start editing

Axis type

The axis type is specified by its property scaleType which expect one of the following values:

  • 'band': Split the axis in equal band. Mostly used for bar charts.
  • 'linear', 'log', 'sqrt': Map numerical values to the space available for the chart. 'linear' is the default behavior.
  • 'time', 'utc': Map JavaScript Date() object to the space available for the chart.

Axis data

The axis definition object also includes a data property. Which expects an array of value coherent with the scaleType:

  • For 'linear', 'log', or 'sqrt' it should contain numerical values
  • For 'time' or 'utc' it should contain Date() objects
  • For 'band' it can contain string, or numerical values

Some series types also require specific axis attributes:

  • line plots require an xAxis to have data provided
  • bar plots require an xAxis with scaleType='band' and some data provided.

Axis sub domain

By default, the axis domain is computed such that all your data is visible. To show a specific range of values, you can provide properties min and/or max to the axis definition.

xAxis={[
  {
    min: 10,
    max: 50,
  }
]}
−25−20−15−10−50510152025x−25−20−15−10−50510152025

Axis customization

You can further customize the axis rendering besides the axis definition.

Position

Charts components provide 4 props: topAxis, rightAxis, bottomAxis, and leftAxis allowing to define the 4 axes of the chart. Those pros can accept three type of value:

  • null to not display the axis
  • string which should correspond to the id of a xAxis for top and bottom. Or to the id of a yAxis for left and right.
  • object which will be passed as props to <XAxis /> or <YAxis />. It allows to specify which axis should be represent, and to customize the design of the axis.
−25−20−15−10−50510152025−25−20−15−10−50510152025
Press Enter to start editing

Rendering

Axes rendering can be further customized. Below is an interactive demonstration of the axis props.

−30−20−100102030my axis
import { ScatterChart } from '@mui/x-charts/ScatterChart';

<ScatterChart
  {/** ... */}
  bottomAxis={{
  }}
/>

Playground

Composition

If you are using composition, you have to provide the axis settings in the <ChartContainer /> by using xAxis and yAxis props.

It will provide all the scaling properties to its children, and allows you to use <XAxis/> and <YAxis/> components as children. Those components require an axisId prop to link them to an axis you defined in the <ChartContainer />.

You can choose their position with position props which accept 'top'/'bottom' for <XAxis /> and 'left'/'right' for <YAxis />. Other props are similar to the ones defined in the previous section.

Q1Q2Q3Q42021 quarters01,0002,0003,0004,0005,0006,0007,0008,0009,000# units sold5,0006,0007,0008,0009,00010,00011,00012,00013,000revenu