{"record":{"id":"934fd58c57fb496f","repo":"tui-cs/Terminal.Gui","slug":"number-of-values-must-match-the-number-of-bars-per","errorCode":null,"errorMessage":"Number of values must match the number of bars per category","messagePattern":"Number of values must match the number of bars per category","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Terminal.Gui/Views/GraphView/MultiBarSeries.cs","lineNumber":81,"sourceCode":"    /// <param name=\"drawBounds\"></param>\n    /// <param name=\"graphBounds\"></param>\n    public void DrawSeries (GraphView graph, Rectangle drawBounds, RectangleF graphBounds)\n    {\n        foreach (BarSeries bar in _subSeries)\n        {\n            bar.DrawSeries (graph, drawBounds, graphBounds);\n        }\n    }\n\n    /// <summary>Adds a new cluster of bars</summary>\n    /// <param name=\"label\"></param>\n    /// <param name=\"fill\"></param>\n    /// <param name=\"values\">Values for each bar in category, must match the number of bars per category</param>\n    public void AddBars (string label, Rune fill, params float [] values)\n    {\n        if (values.Length != _subSeries.Length)\n        {\n            throw new ArgumentException (@\"Number of values must match the number of bars per category\", nameof (values));\n        }\n\n        for (var i = 0; i < values.Length; i++)\n        {\n            _subSeries [i]\n                .Bars.Add (\n                           new (\n                                label,\n                                new (fill),\n                                values [i]\n                               )\n                          );\n        }\n    }\n}\n","sourceCodeStart":63,"sourceCodeEnd":97,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Views/GraphView/MultiBarSeries.cs#L63-L97","documentation":"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.","triggerScenarios":"series.AddBars(\"Q1\", '#', 1f, 2f) on a series created with numberOfBarsPerCategory=3; passing fewer or more values than the constructor specified.","commonSituations":"Changing numberOfBarsPerCategory in the constructor but forgetting to update AddBars call sites; data sourced from an array whose length varies at runtime.","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."],"exampleFix":"// before\nvar s = new MultiBarSeries(3, 1f, 0.5f);\ns.AddBars(\"Q1\", '#', 1f, 2f); // only 2 of 3\n// after\ns.AddBars(\"Q1\", '#', 1f, 2f, 3f);","handlingStrategy":"validation","validationCode":"if (values.Length != series.SubSeries.Count)\n    Array.Resize(ref values, series.SubSeries.Count);\nseries.AddBars (label, fill, values);","typeGuard":"static bool ValuesMatchBars (MultiBarSeries s, float[] v) => v.Length == s.SubSeries.Count;","tryCatchPattern":null,"preventionTips":["Pass exactly numberOfBarsPerCategory values.","Pad/truncate runtime arrays before AddBars.","Store bar count and assert before each AddBars call."],"tags":["graphview","multibarseries","addbars","validation"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}