iOfficeAI/OfficeCLI · error · ArgumentException

logBase cannot be enabled while the axis minimum ({curMin})

Error message

logBase cannot be enabled while the axis minimum ({curMin}) is <= 0: a logarithmic axis minimum must be greater than 0.

What it means

When enabling a log scale (logBase is set to a valid value), the library checks the axis's existing MinAxisValue. A logarithmic axis with min <= 0 produces an invalid file that Excel refuses (0x800A03EC). This guard catches the case where min was set to 0 or negative BEFORE enabling log scale — the reverse of error 131 (which catches min set AFTER log scale).

Source

Thrown at src/officecli/Core/Chart/ChartHelper.Axis.cs:500

                            }
                            else
                            // "0" dropped as a falsy synonym for the same
                            // reason as the Setter.cs site — falls into the
                            // range check below and throws.
                            {
                                var logVal = ParseHelpers.SafeParseDouble(value, "logBase");
                                // ST_LogBase: minInclusive=2.0, maxInclusive=1000.0 — reject
                                // out-of-band values so Excel doesn't silently
                                // ghost-rewrite the chart back to linear.
                                if (logVal < 2.0 || logVal > 1000.0)
                                    throw new ArgumentException($"Invalid logBase '{value}': must be in the OOXML range [2, 1000] (ST_LogBase).");
                                newLogBase = logVal;
                            }
                            // A log scale requires axis min > 0 (Excel refuses
                            // the file, 0x800A03EC).
                            if (newLogBase != null
                                && scaling.GetFirstChild<C.MinAxisValue>()?.Val?.Value is { } curMin && curMin <= 0)
                                throw new ArgumentException(
                                    $"logBase cannot be enabled while the axis minimum ({curMin}) is <= 0: a logarithmic axis minimum must be greater than 0.");
                            scaling.RemoveAllChildren<C.LogBase>();
                            if (newLogBase != null)
                                scaling.PrependChild(new C.LogBase { Val = newLogBase.Value });
                        }
                    }
                    directlyHandled.Add(key);
                    break;
                }

                case "format":
                {
                    // Number-format string written as the axis's NumberingFormat child.
                    // Schema declares format on all roles; apply directly on the resolved axis.
                    if (targetAxis is OpenXmlCompositeElement axNf)
                    {
                        axNf.RemoveAllChildren<C.NumberingFormat>();
                        var nf = new C.NumberingFormat { FormatCode = value, SourceLinked = false };

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Set axismin to a positive value before or together with logbase: axismin=1 then logbase=10.
  2. Remove the existing min constraint: the library will remove it if you clear MinAxisValue first.
  3. Apply log scale and min in the correct order: raise min first, then enable log.

Example fix

// before
axismin=0
logbase=10
// after
axismin=1
logbase=10
Defensive patterns

Strategy: validation

Validate before calling

static bool CanEnableLogBase(OpenXmlCompositeElement axis)
{
    var scaling = axis.GetFirstChild<C.Scaling>();
    if (scaling?.GetFirstChild<C.MinAxisValue>()?.Val?.Value is { } curMin)
        return curMin > 0;
    return true; // no min constraint set
}

Try / catch

try { axisSetter.Apply("logbase", value); }
catch (ArgumentException ex) when (ex.Message.Contains("logBase cannot be enabled"))
{
    Console.Error.WriteLine($"{ex.Message}\nSet axismin to a positive value first.");
}

Prevention

When it happens

Trigger: Setting axismin=0 (or any non-positive value) first, then setting logbase=10 on the same axis. The check reads scaling.GetFirstChild<C.MinAxisValue>()?.Val and verifies it is > 0 before applying the new LogBase.

Common situations: Starting with a default axis min of 0 (common for value axes) and then enabling log scale without first raising the min. Applying a preset configuration that sets min=0 and logbase together in the wrong order. Inheriting an axis with min=0 from a template chart.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/061b34e28344dd16. Report an issue: GitHub.