Skip to content

DonutChartWidget<T> ​

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A widget that displays a donut (or pie) chart using half-block characters for smooth rendering.

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

Inheritance ​

Object → Hex1bWidget → DonutChartWidget<T>

Implements ​

Properties ​

Data ​

Gets the data source for the chart.

Returns: IReadOnlyList<<T>>

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

Methods ​

HoleSize(double) ​

Sets the inner radius as a fraction of the outer radius.

Parameters:

  • ratio (Double): A value between 0.0 (solid pie chart) and 1.0 (thin ring). Default is 0.5.

Returns: DonutChartWidget`1

csharp
public DonutChartWidget<T> HoleSize(double ratio)

Label(Func<T, string>) ​

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

Parameters:

Returns: DonutChartWidget`1

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

Title(string) ​

Sets the chart title displayed above the donut.

Parameters:

Returns: DonutChartWidget`1

csharp
public DonutChartWidget<T> Title(string title)

Value(Func<T, double>) ​

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

Parameters:

Returns: DonutChartWidget`1

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

Remarks ​

DonutChartWidget renders proportional data as colored arc segments around a ring. Each segment's arc length is proportional to its value relative to the sum of all values.

The chart uses Unicode half-block characters (▀/▄) with independent foreground and background colors to achieve 2× vertical resolution, producing smooth circular shapes in the terminal.

Set to 0.0 for a solid pie chart or leave at the default 0.5 for a classic donut.

Use to display a legend alongside this chart.

Examples ​

csharp
ctx.DonutChart([new("Go", 42), new("Rust", 28), new("C#", 30)])
    .Title("Languages")
ctx.Legend([new("Go", 42), new("Rust", 28), new("C#", 30)])
    .ShowPercentages()

Released under the MIT License.