Class
ChartLegend

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

Constructors

ChartLegend()

Declaration

cs-api-definition
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

cs-api-definition
[Parameter]
public ChartLegendAlign? Align { get; set; }

Property Value

ChartLegendAlign?

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

cs-api-definition
[Parameter]
public string Background { get; set; }

Property Value

string

ChildContent

Declaration

cs-api-definition
[Parameter]
public RenderFragment ChildContent { get; set; }

Property Value

RenderFragment

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

cs-api-definition
[Parameter]
public double? Height { get; set; }

Property Value

double?

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

cs-api-definition
[Parameter]
public double? OffsetX { get; set; }

Property Value

double?

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

cs-api-definition
[Parameter]
public double? OffsetY { get; set; }

Property Value

double?

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

cs-api-definition
[Parameter]
public ChartLegendOrientation? Orientation { get; set; }

Property Value

ChartLegendOrientation?

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

cs-api-definition
[Parameter]
public ChartLegendPosition? Position { get; set; }

Property Value

ChartLegendPosition?

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.

Declaration

cs-api-definition
[Parameter]
public bool? Reverse { get; set; }

Property Value

bool?

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

cs-api-definition
[Parameter]
public double? Spacing { get; set; }

Property Value

double?

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.

Declaration

cs-api-definition
[Parameter]
public bool? Visible { get; set; }

Property Value

bool?

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.

Declaration

cs-api-definition
[Parameter]
public double? Width { get; set; }

Property Value

double?

Methods

BuildRenderTree(RenderTreeBuilder)

Declaration

cs-api-definition
protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder

RenderTreeBuilder

Overrides ComponentBase.BuildRenderTree(RenderTreeBuilder)

OnAfterRender(bool)

Declaration

cs-api-definition
protected override void OnAfterRender(bool firstRender)

Parameters

firstRender

bool

Overrides ComponentBase.OnAfterRender(bool)

OnInitialized()

Declaration

cs-api-definition
protected override void OnInitialized()

Overrides DataVizChildComponent.OnInitialized()

OnParametersSet()

Declaration

cs-api-definition
protected override void OnParametersSet()

Overrides ComponentBase.OnParametersSet()

Serialize()

Declaration

cs-api-definition
public Dictionary<string, object> Serialize()

Returns

Dictionary<string, object>