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/ChartsLegend';
// or
import { PiecewiseColorLegend } from '@mui/x-charts-pro';
// or
import { PiecewiseColorLegend } from '@mui/x-charts-premium/ChartsLegend';
// or
import { PiecewiseColorLegend } from '@mui/x-charts-premium';Learn about the difference by reading this guide on minimizing bundle size.
Props of the native component are also available.
| Name | Type | Default | Description |
|---|---|---|---|
| axisDirection | 'x' | 'y' | 'z' | 'z' | The axis direction containing the color configuration to represent. |
| axisId | number | string | The first axis item. | The id of the axis item with the color configuration to represent. |
| classes | Partial | - | 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. |
| labelFormatter | func | - | Format the legend labels. Signature: function(params: PiecewiseLabelFormatterParams) => string | null
|
| labelPosition | 'end' | 'extremes' | 'inline-end' | 'inline-start' | 'start' | 'extremes' | Where to position the labels relative to the color marks. |
| onItemClick | func | - | Callback fired when a legend item is clicked. Signature: function(event: React.MouseEvent<HTMLButtonElement, MouseEvent>, legendItem: PiecewiseColorLegendItemContext, index: number) => void
|
| slotProps | ChartsLegendSlotProps | {} | The props used for each component slot. |
| slots | ChartsLegendSlots | {} | Overridable component slots. See Slots API below for more details. |
| tabIndex | number | - |
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.
| Slot name | Class name | Default component | Description |
|---|---|---|---|
| legend | ChartsLegend | Custom rendering of the legend. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Rule name | Description |
|---|---|---|
| .MuiPiecewiseColorLegend-end | end | Styles applied to the legend with the labels after the color marks. |
| .MuiPiecewiseColorLegend-extremes | extremes | Styles applied to the legend with the labels on the extremes of the color marks. |
| .MuiPiecewiseColorLegend-horizontal | horizontal | Styles applied to the legend in row layout. |
| .MuiPiecewiseColorLegend-inlineEnd | inlineEnd | Styles applied to the legend with the labels inlined after the color marks. |
| .MuiPiecewiseColorLegend-inlineStart | inlineStart | Styles applied to the legend with the labels inlined before the color marks. |
| .MuiPiecewiseColorLegend-item | item | Styles applied to the list items. |
| .MuiPiecewiseColorLegend-label | label | Styles applied to the series label. |
| .MuiPiecewiseColorLegend-mark | mark | Styles applied to the marks. |
| .MuiPiecewiseColorLegend-maxLabel | maxLabel | Styles applied to the list item that renders the `maxLabel`. |
| .MuiPiecewiseColorLegend-minLabel | minLabel | Styles applied to the list item that renders the `minLabel`. |
| .MuiPiecewiseColorLegend-root | root | Styles applied to the root element. |
| .MuiPiecewiseColorLegend-start | start | Styles applied to the legend with the labels before the color marks. |
| .MuiPiecewiseColorLegend-vertical | vertical | Styles applied to the legend in column layout. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
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.