iOfficeAI/OfficeCLI · error · ArgumentException
stock chart requires 3 or 4 data series (high, low, close [,
Error message
stock chart requires 3 or 4 data series (high, low, close [, open]); got {seriesData.Count}. What it means
Stock charts in OOXML (CT_StockChart) require exactly 3 or 4 data series: High-Low-Close (3) or Open-High-Low-Close (4). The minOccurs=3, maxOccurs=4 constraint is schema-enforced; any other count writes a schema-invalid file (e.g. c:hiLowLines appears where the validator still expects c:ser). The library rejects up front rather than emitting broken XML.
Source
Thrown at src/officecli/Core/Chart/ChartHelper.Builder.cs:1373
radarChart.AppendChild(new C.AxisId { Val = catAxisId });
radarChart.AppendChild(new C.AxisId { Val = valAxisId });
return radarChart;
}
// ==================== Stock Chart ====================
internal static C.StockChart BuildStockChart(
string[]? categories, List<(string name, double[] values)> seriesData,
uint catAxisId, uint valAxisId)
{
// Stock chart expects series in Open-High-Low-Close order (4 series)
// or High-Low-Close order (3 series)
// BUG-R6A(BUG2): OOXML CT_StockChart constrains c:ser to minOccurs=3,
// maxOccurs=4. Any other count writes a schema-invalid file (e.g.
// c:hiLowLines appears where the validator still expects c:ser). Reject
// up front with an actionable message rather than emitting broken XML.
if (seriesData.Count is < 3 or > 4)
throw new ArgumentException(
$"stock chart requires 3 or 4 data series (high, low, close [, open]); got {seriesData.Count}.");
var stockChart = new C.StockChart();
for (int i = 0; i < seriesData.Count; i++)
{
var series = new C.LineChartSeries(
new C.Index { Val = (uint)i },
new C.Order { Val = (uint)i },
BuildSeriesText(seriesData[i].name)
);
// Hide individual series lines — stock chart visuals come from
// hiLowLines + upDownBars, not from the series lines themselves
var spPr = new C.ChartShapeProperties();
spPr.AppendChild(new Drawing.Outline(new Drawing.NoFill()));
series.AppendChild(spPr);
View on GitHub (pinned to 1ced45e900)
Solutions
- Provide exactly 3 series (High, Low, Close) in that order.
- Or provide exactly 4 series (Open, High, Low, Close) in OHLC order.
- If you need volume data, use a combo chart (stock+bar) instead of adding a 5th series to the stock chart.
Example fix
// before
series: [{ name: "High", values: [10, 20, 30] }, { name: "Low", values: [5, 10, 15] }]
kind: "stock"
// after (3 series: HLC)
series: [
{ name: "High", values: [10, 20, 30] },
{ name: "Low", values: [5, 10, 15] },
{ name: "Close", values: [8, 15, 25] }
]
kind: "stock"
// or 4 series: OHLC
series: [
{ name: "Open", values: [7, 12, 18] },
{ name: "High", values: [10, 20, 30] },
{ name: "Low", values: [5, 10, 15] },
{ name: "Close", values: [8, 15, 25] }
] Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidStockSeriesCount(int count) => count is >= 3 and <= 4;
// Before building:
if (kind == "stock" && !IsValidStockSeriesCount(seriesData.Count))
throw new ArgumentException(
$"Stock chart requires 3 (HLC) or 4 (OHLC) series; got {seriesData.Count}."); Try / catch
try { ChartHelper.BuildStockChart(categories, seriesData, catAxisId, valAxisId); }
catch (ArgumentException ex) when (ex.Message.StartsWith("stock chart requires"))
{
Console.Error.WriteLine($"{ex.Message}\nProvide 3 series (High, Low, Close) or 4 (Open, High, Low, Close).");
} Prevention
- Provide exactly 3 series (High, Low, Close) or 4 series (Open, High, Low, Close).
- Order matters: HLC or OHLC, not arbitrary order.
- For volume data, use a combo chart (stock+bar), not a 5-series stock chart.
When it happens
Trigger: Building a stock chart with fewer than 3 series (e.g. just high+low) or more than 4 series (e.g. high+low+close+open+volume). The check fires at the top of BuildStockChart before any series elements are constructed.
Common situations: Passing 2 series (high+low) expecting a high-low chart — OOXML requires at least 3. Passing 5 series (adding volume) — exceeds the maxOccurs=4 constraint. Not providing data in the correct OHLC/HLC order. Confusing stock chart requirements with candlestick chart libraries that accept arbitrary series counts.
Related errors
- Invalid logBase '{value}': must be in the OOXML range [2, 10
- Invalid 'tickLabelSkip' value: '{value}'. Must be an integer
- Invalid {lower} '{value}': must be a positive number (OOXML
- 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/9783a971a4faf26b.
Report an issue: GitHub.