BarChart
IBarChart renders a vertical bar chart - one row per item, each with a label, a horizontal filled bar, and an optional numeric value.
![]()
When to use
- Showing scalar metrics across categories - language usage, error counts, benchmark results.
- Quick comparative summaries.
For percentage-of-whole stacked bars, use BreakdownChart.
Basic usage
pascal
var
chart : IBarChart;
begin
chart := Widgets.BarChart.WithLabel('[bold]Languages[/]');
chart.AddItem('Pascal', 80, TAnsiColor.Aqua);
chart.AddItem('Go', 45, TAnsiColor.Lime);
chart.AddItem('Rust', 60, TAnsiColor.Red);
chart.WithWidth(40);
AnsiConsole.Write(chart);
end;1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Configuration
| Method | Purpose |
|---|---|
WithLabel(value) | Title above the chart. Markup supported. |
WithLabelAlignment(value) | TAlignment.Left / Center / Right for the label. |
WithWidth(value) | Total chart width in cells. |
WithMaxValue(value) | Override the implicit max (default = max of all items). |
WithShowValues(value) | Append the numeric value next to each bar. |
pascal
chart
.WithLabel('[bold yellow]Build times[/]')
.WithLabelAlignment(TAlignment.Left)
.WithWidth(60)
.WithShowValues(True);1
2
3
4
5
2
3
4
5
Adding items
pascal
chart.AddItem('label', value, TAnsiColor.Red);1
value is a Double. Color is a TAnsiColor (use the named constants like TAnsiColor.Aqua or build a custom one with TAnsiColor.FromRGB(r, g, b)).
API reference
Widgets.BarChart— empty chart.IBarChart— interface.- Demo:
demos/snippets/BarChart.
See also
- BreakdownChart — single horizontal stacked bar.
- Colours reference.