ClassChartLegend
Configures the chart legend that displays series names, colors, and symbols in TelerikChart. Use this component to help users identify different data series in your chart through visual indicators and descriptive labels. The legend can be positioned around the chart, customized with borders and styling, and configured to show or hide series when clicked. Essential for multi-series charts where users need to understand what each line, bar, or area represents. Children: ChartLegendBorder, ChartLegendItem, ChartLegendLabels, ChartLegendMargin, ChartLegendPadding, ChartLegendTitle.
Definition
Namespace:Telerik.Blazor.Components
Assembly:Telerik.Blazor.dll
Syntax:
public class ChartLegend : DataVizChildComponent, IComponent, IHandleEvent, IHandleAfterRender, IDisposable
Inheritance: objectComponentBaseDataVizChildComponentChartLegend
Implements:
Inherited Members
Constructors
ChartLegend()
Declaration
public ChartLegend()
Properties
Align
Controls the alignment of legend items within the legend container. Start aligns items to the left (horizontal) or top (vertical) for orderly presentation. Center centers items within the legend area for balanced appearance. End aligns items to the right (horizontal) or bottom (vertical) for alternative layouts. Works with Position and Orientation to achieve desired legend layout.
Declaration
[Parameter]
public ChartLegendAlign? Align { get; set; }
Property Value
Background
Sets the background color for the entire legend area using any valid CSS color. Examples: "#F5F5F5", "rgba(245, 245, 245, 0.9)", "lightgray". Use semi-transparent colors like "rgba(255, 255, 255, 0.8)" for overlay effects. Helps distinguish legend from chart content when positioned over the chart area. When not set, uses transparent background allowing chart content to show through.
Declaration
[Parameter]
public string Background { get; set; }
Property Value
ChildContent
Declaration
[Parameter]
public RenderFragment ChildContent { get; set; }
Property Value
Height
Sets the legend height in pixels when using vertical orientation. Only applies when Orientation is set to Vertical. Examples: 200 for compact legends, 400 for standard height, 600 for tall legends. Use when you need to control vertical space allocation for the legend. When not specified, automatically adjusts height based on content.
Declaration
[Parameter]
public double? Height { get; set; }
Property Value
OffsetX
Moves the legend horizontally from its default position in pixels. Positive values shift the legend to the right, negative values shift left. Examples: 20 moves legend 20px right, -15 moves legend 15px left. Use for fine-tuning legend placement when default positioning isn't optimal. Helpful for avoiding overlaps with chart elements or creating custom layouts.
Declaration
[Parameter]
public double? OffsetX { get; set; }
Property Value
OffsetY
Moves the legend vertically from its default position in pixels. Positive values shift the legend down, negative values shift up. Examples: 30 moves legend 30px down, -20 moves legend 20px up. Use for precise vertical positioning when standard legend placement needs adjustment. Essential for avoiding overlaps with chart titles or other elements.
Declaration
[Parameter]
public double? OffsetY { get; set; }
Property Value
Orientation
Controls the layout direction of legend items for optimal space utilization. Horizontal arranges items side-by-side, ideal for bottom/top positioned legends with limited vertical space. Vertical stacks items vertically, perfect for left/right positioned legends or when you have many series. Use horizontal orientation for wide charts and few series, vertical for tall charts or many series. Affects how Width, Height, and Spacing parameters are applied.
Declaration
[Parameter]
public ChartLegendOrientation? Orientation { get; set; }
Property Value
Position
Determines where the legend appears relative to the chart plotting area. Bottom places legend below the chart, ideal for horizontal layouts with standard presentation. Top positions legend above the chart, useful when emphasizing legend importance. Right places legend to the right, perfect for vertical layouts and wide charts. Left positions legend to the left, suitable for alternative layout designs. Custom enables precise positioning using OffsetX and OffsetY for overlay scenarios. Consider chart dimensions and series count when choosing position for optimal user experience.
Declaration
[Parameter]
public ChartLegendPosition? Position { get; set; }
Property Value
Reverse
Reverses the display order of legend items from their default sequence. When true, legend items appear in reverse order of how series are defined. Useful for matching legend order with visual stacking order in stacked charts. Helpful when the most important series appears last but should be shown first in legend. Default false maintains the original series order.
Spacing
Controls horizontal spacing between legend items in pixels. Only applies when Orientation is set to Horizontal. Examples: 10 for compact spacing, 20 for standard, 40 for loose spacing. Use smaller values when space is limited or when you have many series. Larger values improve readability when you have few series with long names.
Declaration
[Parameter]
public double? Spacing { get; set; }
Property Value
Visible
Controls whether the legend appears in the chart visualization. Set to false to hide the legend when series identification isn't needed. Useful for simple charts with obvious data meaning or when space is limited. Hidden legends free up space for larger chart plotting area. Default true shows the legend for better data interpretation.
Width
Sets the legend width in pixels when using horizontal orientation. Only applies when Orientation is set to Horizontal. Examples: 300 for narrow legends, 600 for standard width, 900 for wide legends. Use when you need to control horizontal space allocation for the legend. When not specified, automatically adjusts width based on content and available space.
Methods
BuildRenderTree(RenderTreeBuilder)
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builder
Overrides
OnAfterRender(bool)
Declaration
protected override void OnAfterRender(bool firstRender)
Parameters
firstRender
Overrides
OnInitialized()
Declaration
protected override void OnInitialized()
Overrides
OnParametersSet()
Declaration
protected override void OnParametersSet()
Overrides
Serialize()
Declaration
public Dictionary<string, object> Serialize()
Returns