Skip to content

LegendWidget<T>

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A standalone widget that displays a chart legend with colored swatches and labels.

csharp
public sealed record LegendWidget<T> : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<LegendWidget<T>>

Inheritance

ObjectHex1bWidgetLegendWidget<T>

Implements

Properties

Data

Gets the data source for the legend.

Returns: IReadOnlyList<<T>>

csharp
public IReadOnlyList<T>? Data { get; init; }

ValueFormatter

Gets the custom value formatter for legend display. When null, the default chart formatter is used.

Returns: Func<Double, String>

csharp
public Func<double, string>? ValueFormatter { get; init; }

Methods

FormatValue(Func<double, string>)

Sets a custom value formatter for legend display.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> FormatValue(Func<double, string> formatter)

Horizontal(bool)

Sets the legend to render items horizontally on a single row.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> Horizontal(bool horizontal = true)

Label(Func<T, string>)

Sets the function that extracts a label from each data item.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> Label(Func<T, string> selector)

ShowPercentages(bool)

Sets whether to display percentages in the legend.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> ShowPercentages(bool show = true)

ShowValues(bool)

Sets whether to display absolute values in the legend.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> ShowValues(bool show = true)

Value(Func<T, double>)

Sets the function that extracts the numeric value from each data item.

Parameters:

Returns: LegendWidget`1

csharp
public LegendWidget<T> Value(Func<T, double> selector)

Remarks

LegendWidget renders a list of labeled color swatches, optionally showing values and/or percentages. It can be placed anywhere in the widget tree independently of chart widgets.

Supports both vertical (one item per row) and horizontal (all items on one row) orientation via .

Examples

csharp
ctx.DonutChart(data).FillHeight()
ctx.Legend(data).ShowPercentages().Horizontal()

Released under the MIT License.