tui-cs/Terminal.Gui · error · ArgumentException
Number of values must match the number of bars per category
Error message
Number of values must match the number of bars per category
What it means
AddBars adds a cluster of bars to a MultiBarSeries. Each cluster must contain exactly one value per bar-in-category (the count passed to the constructor). A mismatched values array would leave some bars empty or index out of range, so it is rejected.
Source
Thrown at Terminal.Gui/Views/GraphView/MultiBarSeries.cs:81
/// <param name="drawBounds"></param>
/// <param name="graphBounds"></param>
public void DrawSeries (GraphView graph, Rectangle drawBounds, RectangleF graphBounds)
{
foreach (BarSeries bar in _subSeries)
{
bar.DrawSeries (graph, drawBounds, graphBounds);
}
}
/// <summary>Adds a new cluster of bars</summary>
/// <param name="label"></param>
/// <param name="fill"></param>
/// <param name="values">Values for each bar in category, must match the number of bars per category</param>
public void AddBars (string label, Rune fill, params float [] values)
{
if (values.Length != _subSeries.Length)
{
throw new ArgumentException (@"Number of values must match the number of bars per category", nameof (values));
}
for (var i = 0; i < values.Length; i++)
{
_subSeries [i]
.Bars.Add (
new (
label,
new (fill),
values [i]
)
);
}
}
}
View on GitHub (pinned to 2e47b11478)
Solutions
- Pass exactly numberOfBarsPerCategory values in every AddBars call.
- Pad or truncate the values array to match _subSeries.Length before calling.
- Store numberOfBarsPerCategory and assert values.Length matches it before AddBars.
Example fix
// before
var s = new MultiBarSeries(3, 1f, 0.5f);
s.AddBars("Q1", '#', 1f, 2f); // only 2 of 3
// after
s.AddBars("Q1", '#', 1f, 2f, 3f); Defensive patterns
Strategy: validation
Validate before calling
if (values.Length != series.SubSeries.Count)
Array.Resize(ref values, series.SubSeries.Count);
series.AddBars (label, fill, values); Type guard
static bool ValuesMatchBars (MultiBarSeries s, float[] v) => v.Length == s.SubSeries.Count;
Prevention
- Pass exactly numberOfBarsPerCategory values.
- Pad/truncate runtime arrays before AddBars.
- Store bar count and assert before each AddBars call.
When it happens
Trigger: series.AddBars("Q1", '#', 1f, 2f) on a series created with numberOfBarsPerCategory=3; passing fewer or more values than the constructor specified.
Common situations: Changing numberOfBarsPerCategory in the constructor but forgetting to update AddBars call sites; data sourced from an array whose length varies at runtime.
Related errors
- Number of colors must match the number of bars
- OmitClassName is not allowed when Scope is AppSettingsScope
- Provided text is too short to be any known color format.
- The text provided was null or empty.
- The text provided consisted of only whitespace characters.
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/934fd58c57fb496f.
Report an issue: GitHub.