Purpose
Based on the source implementation in~/workspace/source/src/component/legend/LegendModel.ts, the legend component:
- Displays symbolic representations of data series with their names
- Supports interactive selection/deselection of series
- Provides selector buttons for bulk operations (select all, inverse selection)
- Automatically derives legend items from series data or accepts custom configuration
- Supports both plain and scrollable layouts for handling many legend items
Basic Usage
Legend with Selector Buttons
Styled Legend Items
Configuration Options
Core Properties
Whether to display the legend component.
Layout orientation of the legend. From
~/workspace/source/src/component/legend/LegendModel.ts:455.Distance from the left side of the container. Can be pixel value or percentage.
Distance from the top of the container.
Distance from the right side of the container.
Distance from the bottom of the container.
Alignment of legend items. Auto alignment is based on the position and orientation.
Item Styling
Width of the legend symbol. Defined in
LegendModel.ts:470.Height of the legend symbol. Defined in
LegendModel.ts:471.Gap between each legend item. From
LegendModel.ts:469.Icon type for legend items. Can be ‘circle’, ‘rect’, ‘roundRect’, ‘triangle’, ‘diamond’, ‘pin’, ‘arrow’, or a custom SVG path.
Rotation angle of the legend symbol. Set to ‘inherit’ to use the series symbol rotation.
Color when legend item is not selected. Implementation in
LegendModel.ts:475.Border color when legend item is not selected.
Selection Mode
Selection mode for legend items:
trueor'multiple': Multiple items can be selected'single': Only one item can be selected at a timefalse: Selection is disabled
LegendModel.ts:388-398.Default selection state for legend items. Object with item names as keys and boolean values.
Selector Configuration
Buttons for select all or inverse select operations. Can be:
true: Show both ‘all’ and ‘inverse’ buttons['all', 'inverse']: Specify which buttons to show- Array of objects with custom configuration
LegendModel.ts:279-293 for implementation.Position of selector buttons relative to legend items.
Gap between each selector button. From
LegendModel.ts:530.Gap between selector buttons and legend items. From
LegendModel.ts:532.Data Configuration
Array of legend item names or configuration objects. If not specified, automatically derived from series data.See
LegendModel.ts:359-381 for data processing.Legend label formatter. Can be a template string or function:
Background and Border
Background color of the legend component.
Border color of the legend box. From
LegendModel.ts:465.Border width of the legend box.
Border radius of the legend box.
Padding inside the legend box. Can be a single number or array [top, right, bottom, left].
Text Styling
Text style configuration for legend labels. Default color from
LegendModel.ts:503-505.Advanced Styling
Style configuration for legend item symbols. Supports ‘inherit’ to use series styles.Properties defined in
LegendModel.ts:479-488.Line style for line series legend items. Includes special properties:
inactiveColor: Line color when item is not selectedinactiveWidth: Line width when item is not selected
LegendModel.ts:490-501.Methods
The LegendModel provides several methods for programmatic control (fromLegendModel.ts):
select(name): Select a legend item (lines 388-398)unSelect(name): Unselect a legend item (lines 400-404)toggleSelected(name): Toggle selection state (lines 406-413)allSelect(): Select all legend items (lines 415-421)inverseSelect(): Inverse current selection (lines 423-434)isSelected(name): Check if an item is selected (lines 436-440)
Events
Whether to trigger legend events that can be caught by the user. From
LegendModel.ts:538.Tooltip
Tooltip configuration for legend items. Default from
LegendModel.ts:534-536.