iOfficeAI/OfficeCLI · error · ArgumentException
Invalid colorRule '{spec}'. Expected: threshold:belowColor:a
Error message
Invalid colorRule '{spec}'. Expected: threshold:belowColor:aboveColor (e.g. '0:FF0000:00AA00') or low:lowColor:mid:midColor:high:highColor (e.g. '0:FF0000:50:FFAA00:100:00AA00'). What it means
The conditional coloring rule (colorRule) applies threshold-based coloring to chart data points. The spec is colon-delimited: either a simple 3-part form (threshold:belowColor:aboveColor) or a multi-zone form (t1:c1:t2:c2:...:cN). If the spec has fewer than 3 parts, the library rejects it immediately with the expected format. The minimum 3 parts ensures at least one threshold, one below-color, and one above-color.
Source
Thrown at src/officecli/Core/Chart/ChartHelper.Advanced.cs:299
or "longdashdot" or "lgdashdot"
or "longdashdotdot" or "lgdashdotdot" => true,
_ => false
};
}
// ==================== Conditional Coloring ====================
/// <summary>
/// Apply conditional coloring to data points based on value thresholds.
/// Format: "threshold:belowColor:aboveColor" or "low:lowColor:mid:midColor:high:highColor"
/// Simple: "0:FF0000:00AA00" — below 0 = red, above 0 = green
/// Three-tier: "0:FF0000:50:FFAA00:100:00AA00" — red/orange/green zones
/// </summary>
internal static void ApplyColorRule(C.PlotArea plotArea, string spec)
{
var parts = spec.Split(':');
if (parts.Length < 3)
throw new ArgumentException(
$"Invalid colorRule '{spec}'. Expected: threshold:belowColor:aboveColor (e.g. '0:FF0000:00AA00') " +
"or low:lowColor:mid:midColor:high:highColor (e.g. '0:FF0000:50:FFAA00:100:00AA00').");
var rules = new List<(double threshold, string color)>();
string topColor;
if (parts.Length == 3)
{
// Simple two-zone: threshold:belowColor:aboveColor
if (!double.TryParse(parts[0], System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out var t))
throw new ArgumentException($"Invalid threshold '{parts[0]}' in colorRule. Expected a number.");
rules.Add((t, parts[1].Trim()));
topColor = parts[2].Trim();
}
else
{
// Multi-zone: t1:c1:t2:c2:...:cNView on GitHub (pinned to 1ced45e900)
Solutions
- Provide at least 3 parts: threshold:belowColor:aboveColor, e.g. '0:FF0000:00AA00'.
- For multi-zone coloring, provide alternating threshold:color pairs with an optional trailing top color.
- Ensure you use ':' as the delimiter, not ',' or ';'.
Example fix
// before colorrule: "FF0000:00AA00" // after colorrule: "0:FF0000:00AA00" // three-zone colorrule: "0:FF0000:50:FFAA00:100:00AA00"
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidColorRuleSpec(string spec)
{
var parts = spec.Split(':');
return parts.Length >= 3;
} Try / catch
try { ChartHelperAdvanced.ApplyColorRule(plotArea, spec); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid colorRule"))
{
Console.Error.WriteLine($"{ex.Message}\nExpected: threshold:belowColor:aboveColor or multi-zone.");
} Prevention
- Always provide at least 3 segments: threshold:belowColor:aboveColor.
- Use ':' as the delimiter consistently.
- Validate segment count before calling ApplyColorRule.
When it happens
Trigger: Passing a colorRule spec with fewer than 3 colon-separated segments: 'FF0000' (1 part), '0:FF0000' (2 parts), or an empty string. Called from ApplyColorRule which is invoked by the Setter case 'colorrule'.
Common situations: Forgetting the above-threshold color. Passing a single hex color instead of a threshold:color:color triple. Using a different delimiter (comma, semicolon) instead of colon. Copying a partial spec from documentation.
Related errors
- Invalid threshold '{parts[0]}' in colorRule. Expected a numb
- Invalid threshold '{parts[i]}' in colorRule.
- invalid_format
- Invalid legend position '{posSpec}'. Valid: none, top, botto
- Invalid referenceLine value '{parts[0]}'. Expected: number o
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/9fddd18775f2b56c.
Report an issue: GitHub.