← Back to Home • Next: ChartBar — Styles →
How the ChartBar control behaves while it is running: keyboard, adding items, ordering, legends,
layouts, paging, and validation.
Select item ← prompt
Selected: North (34.3%) ← description (optional / dynamic)
Sales by Region ← title (ChartTitle)
› North ████████████████████ 120 34% ← highlighted bar + value + percent
South █████████████ 80 23%
East ███████████████ 95 27%
West ██████████████████ 110 31%
North 120 (34%) South 80 (23%) … ← legend (when ShowLegends)
Page 1/2 ← pagination (when PageSize > 0)
Enter: confirm Esc: cancel F2/F3/F4 ← tooltip
Every region can be recolored — see Styles.
| Key | Action |
|---|---|
↑ / ↓ |
Move the highlight between bars (in Stacked layout, ←/→ do the same) |
Page Up / Page Down |
Jump one page |
Ctrl+Home / Ctrl+End |
First / last bar (plain Home/End do not do this) |
F2 |
Switch layout Standard ⇄ Stacked (unless disabled) |
F3 |
Toggle the legend on / off — only works once ShowLegends() has been called at least once; inert otherwise |
F4 |
Cycle the sort order |
Enter |
Confirm the highlighted bar (runs validation) |
Esc |
Abort → IsAborted == true |
F1 |
Cycle tooltip content |
Ctrl+F1 |
Show / hide the tooltip |
AddItem(label, value) adds one bar. There is no AddItems; add many with a
loop or with Interaction.Color to AddItem, or omit it and the control assigns colors in
a rotating sequence.Percent is its share of the total of all values, and
is exposed on the returned ChartItem.Culture and
FractionalDigits (default 2 digits).Layout sets the starting layout: Standard (one bar per item) or Stacked
(all items in one continuous bar).EnableLayoutSwitcher(false)
is set.Stacked requires enough console width to render every item; if the console is too
narrow the switch is silently prevented to avoid broken rendering.OrderBy sets the initial order: None, Highest, Smallest, LabelAsc,
or LabelDesc.ChartBarOrder.None is a no-op — it keeps the original insertion order (the sequential
auto-id order); it never reshuffles the bars.EnableOrderingSwitcher(false) is set.ChartOrder).ShowLegends() adds a legend after the chart listing each item with its
value and percentage. It is off by default.ShowLegends() was called at
least once before Run(). If you never call it, F3 does nothing; there’s no way to turn
legends on for the first time from the keyboard.HideElements removes the title, values, and/or percentages from the
chart. HideChart is a [Flags] enum, so combine with |.PageSize limits how many bars are shown at once; 0 (default) does not
disable paging — it auto-computes a page size that fits the terminal height. Page Up / Page Down
move between pages and the page indicator appears whenever there’s more than one page.Pressing Enter on the highlighted bar:
PredicateSelected /
PredicateSelectedAsync, if configured.ChartItem.
Invalid → the chart stays open and shows the error line.The predicate receives the ChartItem, so you can validate on Value, Label, Percent, or Id:
PromptPlus.Controls.ChartBar("Select item")
.AddItem("Valid", 80).AddItem("Invalid", 30)
.PredicateSelected(item => item.Value < 50
? (false, "Value must be >= 50")
: (true, null))
.Run();
Run() returns ResultPrompt<ChartItem?> — the item highlighted at the moment Enter was pressed,
not a sum or aggregate.
var result = PromptPlus.Controls.ChartBar("Select item")
.AddItem("A", 40).AddItem("B", 85)
.Run();
if (result.IsAborted)
PromptPlus.Console.WriteLine("Canceled.");
else if (result.Content is not null)
PromptPlus.Console.WriteLine($"{result.Content.Label} = {result.Content.Value} ({result.Content.Percent:F2}%)");
ChangeDescription recomputes the description from the currently
highlighted item as the user navigates — handy for showing the live label, value, or percentage.
Set per instance via Options(...), or globally on
PromptPlus.Config:
| Option | Effect on ChartBar |
|---|---|
EnabledAbortKey(false) |
Removes Esc — the user must confirm a bar |
HideAfterFinish(true) |
Erases the chart after confirm — the whole control is erased, not just the interactive part |
ShowTooltip(false) |
Hides the keyboard hint line |
Prompt(...) / Description(...) |
Overrides the prompt / description text |
.Content == null. Always branch on IsAborted (and null-check
.Content) before use.Width below 10 throws; keep the chart at least 10
characters wide.Options