iOfficeAI/OfficeCLI · error · ArgumentException
Invalid threshold '{parts[i]}' in colorRule.
Error message
Invalid threshold '{parts[i]}' in colorRule. What it means
In the multi-zone colorRule form (t1:c1:t2:c2:...:cN), every odd-indexed segment (parts[0], parts[2], ...) must be a numeric threshold. The parser iterates in steps of 2 and checks each threshold. If any threshold fails double.TryParse, the library rejects it with 'Invalid threshold'. This is the multi-zone path (parts.Length != 3); the simple path has its own error (error 128).
Source
Thrown at src/officecli/Core/Chart/ChartHelper.Advanced.cs:322
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:...:cN
for (int i = 0; i < parts.Length - 1; i += 2)
{
if (!double.TryParse(parts[i], System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out var t))
throw new ArgumentException($"Invalid threshold '{parts[i]}' in colorRule.");
rules.Add((t, parts[i + 1].Trim()));
}
topColor = parts.Length % 2 == 1 ? parts[^1].Trim() : rules[^1].color;
if (parts.Length % 2 == 0)
rules.RemoveAt(rules.Count - 1); // Last pair has no "above" — use as topColor
}
// Apply to each data point in each series
foreach (var ser in plotArea.Descendants<OpenXmlCompositeElement>().Where(e => e.LocalName == "ser"))
{
var values = ReadNumericData(ser.GetFirstChild<C.Values>())
?? ReadNumericData(ser.Elements<OpenXmlCompositeElement>().FirstOrDefault(e => e.LocalName == "yVal"));
if (values == null) continue;
for (int pi = 0; pi < values.Length; pi++)
{
var val = values[pi];
string pointColor = topColor;View on GitHub (pinned to 1ced45e900)
Solutions
- Ensure every odd-positioned segment (0-indexed: 0, 2, 4, ...) is a numeric threshold: '0:FF0000:50:FFAA00:100:00AA00'.
- Verify the segment count matches the intended threshold:color pairs plus an optional trailing top color.
- Check for accidental extra colons that misalign the threshold/color pattern.
Example fix
// before colorrule: "0:FF0000:abc:00AA00:100:FFFF00" // after colorrule: "0:FF0000:50:00AA00:100:FFFF00"
Defensive patterns
Strategy: validation
Validate before calling
static bool AreMultiZoneThresholdsNumeric(string spec)
{
var parts = spec.Split(':');
if (parts.Length <= 3) return true; // not multi-zone
for (int i = 0; i < parts.Length - 1; i += 2)
{
if (!double.TryParse(parts[i], System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out _))
return false;
}
return true;
} Try / catch
try { ChartHelperAdvanced.ApplyColorRule(plotArea, spec); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid threshold") && !ex.Message.Contains("Expected a number"))
{
Console.Error.WriteLine($"A threshold in multi-zone colorRule is non-numeric.");
} Prevention
- In multi-zone specs, every even-indexed segment (0, 2, 4, ...) must be numeric.
- Maintain the alternating threshold:color:threshold:color pattern.
- Count segments carefully — an extra colon shifts the alignment.
When it happens
Trigger: Passing a multi-zone colorRule where any threshold segment is non-numeric: '0:FF0000:abc:00AA00' or 'x:FF0000:50:00AA00:100:FFFF00'. The spec must have more than 3 colon-separated parts.
Common situations: Mismatching the alternating threshold:color pattern — placing a color where a threshold belongs. Using locale-specific decimal separators. Adding an extra colon that shifts the even/odd alignment of segments.
Related errors
- Invalid threshold '{parts[0]}' in colorRule. Expected a numb
- Invalid colorRule '{spec}'. Expected: threshold:belowColor:a
- Invalid referenceLine value '{parts[0]}'. Expected: number o
- Invalid referenceLine width '{widthStr}'. Expected a number
- Invalid legend position '{posSpec}'. Valid: none, top, botto
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/ad1ffc1b0467315b.
Report an issue: GitHub.