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.
| Name | Type | Default | Description | 
|---|---|---|---|
| direction* | 'column' | 'row'  | - | The direction of the legend layout. The default depends on the chart.  | 
| position* | { horizontal: 'left' | 'middle' | 'right', vertical: 'bottom' | 'middle' | 'top' }  | - | The position of the legend.  | 
| 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 | object | - | Override or extend the styles applied to the component. See CSS classes API below for more details.  | 
| hideFirst | bool | false | Hide the first item of the legend, corresponding to the [-infinity, min] piece.  | 
| hideLast | bool | false | Hide the last item of the legend, corresponding to the [max, +infinity] piece.  | 
| itemGap | number | 10 | Space between two legend items (in px).  | 
| itemMarkHeight | number | 20 | Height of the item mark (in px).  | 
| itemMarkWidth | number | 20 | Width of the item mark (in px).  | 
| labelFormatter | func | - | Format the legend labels. Signature: function(params: PiecewiseLabelFormatterParams) => string | null
 Returns: The displayed label, or   | 
| labelStyle | object | theme.typography.subtitle1 | Style applied to legend labels.  | 
| markGap | number | 5 | Space between the mark and the label (in px).  | 
| onItemClick | func | - | Callback fired when a legend item is clicked. Signature: function(event: React.MouseEvent
  | 
| padding | number | { bottom?: number, left?: number, right?: number, top?: number }  | 10 | Legend padding (in px). Can either be a single number, or an object with top, left, bottom, right properties.  | 
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-column | column | Styles applied to the legend with column layout. | 
| .MuiPiecewiseColorLegend-itemBackground | itemBackground | Styles applied to the item background. | 
| .MuiPiecewiseColorLegend-label | label | Styles applied to the series label. | 
| .MuiPiecewiseColorLegend-mark | mark | Styles applied to series mark element. | 
| .MuiPiecewiseColorLegend-root | root | Styles applied to the root element. | 
| .MuiPiecewiseColorLegend-row | row | Styles applied to the legend with row layout. | 
| .MuiPiecewiseColorLegend-series | series | Styles applied to a series element. | 
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.