Skip to content

ChartsLegend API

API reference docs for the React ChartsLegend component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import { ChartsLegend } from '@mui/x-charts/ChartsLegend';
// or
import { ChartsLegend } from '@mui/x-charts';
// or
import { ChartsLegend } from '@mui/x-charts-pro';

Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

direction'horizontal'
| 'vertical'
-

The direction of the legend layout. The default depends on the chart.

onItemClickfunc-

Callback fired when a legend item is clicked.

Signature:function(event: React.MouseEvent, legendItem: SeriesLegendItemContext, index: number) => void
  • event The click event.
  • legendItem The legend item data.
  • index The index of the clicked legend item.
slotPropsobject{}

The props used for each component slot.

slotsobject{}

Overridable component slots.

See Slots API below for more details.

The ref is forwarded to the root element.

Theme default props

You can use MuiChartsLegend to change the default props of this component with the theme.

Slots

Slot nameClass nameDefault componentDescription
legendChartsLegendCustom rendering of the legend.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.MuiChartsLegend-horizontalhorizontalStyles applied to the legend in row layout.
.MuiChartsLegend-labellabelStyles applied to the series label.
.MuiChartsLegend-markmarkStyles applied to series mark element.
.MuiChartsLegend-rootrootStyles applied to the root element.
.MuiChartsLegend-seriesseriesStyles applied to a series element.
.MuiChartsLegend-verticalverticalStyles applied to the legend in column layout.

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.