{"record":{"id":"36ed72e3ba52b125","repo":"iOfficeAI/OfficeCLI","slug":"invalid-minorunit-value-must-be-a-positive-nu","errorCode":null,"errorMessage":"Invalid minorUnit '{value}': must be a positive number (OOXML ST_AxisUnit > 0).","messagePattern":"Invalid minorUnit '(.+?)': must be a positive number \\(OOXML ST_AxisUnit > 0\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/Chart/ChartHelper.Setter.cs","lineNumber":1057,"sourceCode":"                    // OOXML ST_AxisUnit: positive double. 0 or negative would\n                    // make Excel refuse to draw any tick on the axis (or, in\n                    // older builds, freeze the chart). Reject up front instead\n                    // of writing garbage that opens to a blank plot area.\n                    if (!(mu > 0))\n                        throw new ArgumentException($\"Invalid majorUnit '{value}': must be a positive number (OOXML ST_AxisUnit > 0).\");\n                    valAxis.RemoveAllChildren<C.MajorUnit>();\n                    InsertValAxChildInOrder(valAxis, new C.MajorUnit { Val = mu });\n                    break;\n                }\n\n                case \"minorunit\":\n                {\n                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();\n                    var valAxis = plotArea2?.GetFirstChild<C.ValueAxis>();\n                    if (valAxis == null) { unsupported.Add(key); break; }\n                    var nu = ParseHelpers.SafeParseDouble(value, \"minorunit\");\n                    if (!(nu > 0))\n                        throw new ArgumentException($\"Invalid minorUnit '{value}': must be a positive number (OOXML ST_AxisUnit > 0).\");\n                    valAxis.RemoveAllChildren<C.MinorUnit>();\n                    InsertValAxChildInOrder(valAxis, new C.MinorUnit { Val = nu });\n                    break;\n                }\n\n                case \"axisnumfmt\" or \"axisnumberformat\":\n                {\n                    var plotArea2 = chart.GetFirstChild<C.PlotArea>();\n                    var valAxis = plotArea2?.GetFirstChild<C.ValueAxis>();\n                    if (valAxis == null) { unsupported.Add(key); break; }\n                    valAxis.RemoveAllChildren<C.NumberingFormat>();\n                    var nf = new C.NumberingFormat { FormatCode = value, SourceLinked = false };\n                    // Schema order: ...title, numFmt, majorTickMark... — insert before majorTickMark\n                    var nfInsertBefore = valAxis.GetFirstChild<C.MajorTickMark>();\n                    if (nfInsertBefore != null) valAxis.InsertBefore(nf, nfInsertBefore);\n                    else valAxis.AppendChild(nf);\n                    break;\n                }","sourceCodeStart":1039,"sourceCodeEnd":1075,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/Chart/ChartHelper.Setter.cs#L1039-L1075","documentation":"Thrown when 'minorUnit' is not a positive number — the same ST_AxisUnit constraint as majorUnit. Non-numeric input is rejected earlier by SafeParseDouble; this throw covers a parsed value <= 0.","triggerScenarios":"SetChartProperties with { [\"minorUnit\"] = \"0\" } or a negative number.","commonSituations":"Reusing majorUnit as minorUnit without halving it; defaulting to 0 when the source had no minor tick; data-driven interval that underflows to 0.","solutions":["Pass a strictly positive minorUnit, typically less than majorUnit.","Omit minorUnit to let Excel auto-derive it.","Guard computed values: if (nu <= 0) skip the key."],"exampleFix":"// before\nSetChartProperties(part, new() { [\"minorUnit\"] = \"0\" });\n// after\nvar minor = major / 2.0;\nif (minor > 0)\n    SetChartProperties(part, new() { [\"minorUnit\"] = minor.ToString(CultureInfo.InvariantCulture) });","handlingStrategy":"validation","validationCode":"static bool IsValidAxisUnit(string v, out double unit) =>\n    double.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out unit)\n    && unit > 0;","typeGuard":"static bool IsPositiveUnit(double v) => v > 0 && !double.IsInfinity(v);","tryCatchPattern":"try { SetChartProperties(part, props); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Invalid minorUnit\"))\n{ /* omit minorUnit to let Excel auto-derive */ }","preventionTips":["Derive minorUnit from majorUnit (e.g. major/2) and re-check positivity.","Omit minorUnit when you have no specific requirement.","Guard data-driven intervals against underflow to 0."],"tags":["ooxml","chart","input-validation","axis","csharp"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}