Skip to content

PiecewiseColorLegend API

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

Demos

Import

import { PiecewiseColorLegend } from '@mui/x-charts/ChartsLegend';
// or
import { PiecewiseColorLegend } from '@mui/x-charts';
// or
import { PiecewiseColorLegend } 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
axisDirection'x'
| 'y'
| 'z'
'z'

The axis direction containing the color configuration to represent.

axisIdnumber
| string
The first axis item.

The id of the axis item with the color configuration to represent.

classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

direction'horizontal'
| 'vertical'
'horizontal'

The direction of the legend layout.

labelFormatterfunc-

Format the legend labels.

Signature:function(params: PiecewiseLabelFormatterParams) => string | null
  • params The bound of the piece to format.

Returns: The displayed label, '' to skip the label but show the color mark, or null to skip it entirely.

labelPosition'start'
| 'end'
| 'extremes'
'extremes'

Where to position the labels relative to the gradient.

markType'square'
| 'circle'
| 'line'
'square'

The type of the mark.

onItemClickfunc-

Callback fired when a legend item is clicked.

Signature:function(event: React.MouseEvent, legendItem: PiecewiseColorLegendItemContext, index: number) => void
  • event The click event.
  • legendItem The legend item data.
  • index The index of the clicked legend item.
The ref is forwarded to the root element.

Theme default props

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

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
.MuiPiecewiseColorLegend-endendStyles applied to the legend with the labels after the color marks.
.MuiPiecewiseColorLegend-extremesextremesStyles applied to the legend with the labels on the extremes of the color marks.
.MuiPiecewiseColorLegend-horizontalhorizontalStyles applied to the legend in row layout.
.MuiPiecewiseColorLegend-itemitemStyles applied to the list items.
.MuiPiecewiseColorLegend-labellabelStyles applied to the series label.
.MuiPiecewiseColorLegend-markmarkStyles applied to the marks.
.MuiPiecewiseColorLegend-maxLabelmaxLabelStyles applied to the list item that renders the maxLabel.
.MuiPiecewiseColorLegend-minLabelminLabelStyles applied to the list item that renders the minLabel.
.MuiPiecewiseColorLegend-rootrootStyles applied to the root element.
.MuiPiecewiseColorLegend-startstartStyles applied to the legend with the labels before the color marks.
.MuiPiecewiseColorLegend-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.