Skip to content

BreakdownChart

IBreakdownChart renders a single horizontal bar split into coloured segments proportional to each item's value. Below the bar sits a legend showing labels and values.

When to use

  • Showing parts-of-a-whole - language mix in a repo, share of resources, etc.
  • Compact alternative to a pie chart (which terminals don't render well).

For per-category vertical bars, use BarChart.

Basic usage

pascal
var
  brk : IBreakdownChart;
begin
  brk := Widgets.BreakdownChart;
  brk.AddItem('Elixir', 35, TAnsiColor.Fuchsia);
  brk.AddItem('C#',     27, TAnsiColor.Aqua);
  brk.AddItem('Ruby',   15, TAnsiColor.Red);
  brk.WithWidth(50);
  AnsiConsole.Write(brk);
end;

Configuration

MethodPurpose
WithWidth(value)Bar width in cells.
WithShowPercentage(value)Show a (NN%) next to each legend item. Default True.
WithShowTags(value)Show legend tags (the colour swatch + label). Default True.
WithShowTagValues(value)Show the numeric value next to each tag.
WithCompact(value)Render the legend on a single line (or wrapped tightly).

Adding items

pascal
brk.AddItem('label', value, TAnsiColor.Red);

API reference

See also

Released under the MIT License.