LegendWidget<T>
Namespace: Hex1b.Widgets
Assembly: Hex1b.dll
A standalone widget that displays a chart legend with colored swatches and labels.
public sealed record LegendWidget<T> : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<LegendWidget<T>>Inheritance
Object → Hex1bWidget → LegendWidget<T>
Implements
Properties
Data
Gets the data source for the legend.
Returns: IReadOnlyList<<T>>
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>
public Func<double, string>? ValueFormatter { get; init; }Methods
FormatValue(Func<double, string>)
Sets a custom value formatter for legend display.
Parameters:
formatter(Func<Double, String>):
Returns: LegendWidget`1
public LegendWidget<T> FormatValue(Func<double, string> formatter)Horizontal(bool)
Sets the legend to render items horizontally on a single row.
Parameters:
horizontal(Boolean):
Returns: LegendWidget`1
public LegendWidget<T> Horizontal(bool horizontal = true)Label(Func<T, string>)
Sets the function that extracts a label from each data item.
Parameters:
selector(Func<<T>, String>):
Returns: LegendWidget`1
public LegendWidget<T> Label(Func<T, string> selector)ShowPercentages(bool)
Sets whether to display percentages in the legend.
Parameters:
show(Boolean):
Returns: LegendWidget`1
public LegendWidget<T> ShowPercentages(bool show = true)ShowValues(bool)
Sets whether to display absolute values in the legend.
Parameters:
show(Boolean):
Returns: LegendWidget`1
public LegendWidget<T> ShowValues(bool show = true)Value(Func<T, double>)
Sets the function that extracts the numeric value from each data item.
Parameters:
selector(Func<<T>, Double>):
Returns: LegendWidget`1
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
ctx.DonutChart(data).FillHeight()
ctx.Legend(data).ShowPercentages().Horizontal()