iOfficeAI/OfficeCLI · error · ArgumentException
Cannot add a series: the chart has no existing series to der
Error message
Cannot add a series: the chart has no existing series to derive structure from. Recreate the chart with the desired series instead.
What it means
Thrown when ChartHelper.AddSeries returns 0, meaning the chart's plot area has no existing series to use as a structural template. AddSeries derives the new series' type, axis, and formatting from the last existing series; an empty chart has nothing to clone from. The fix is to recreate the chart rather than try to bootstrap series into a series-less chart.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs:426
if (cells != null)
properties["values"] = string.Join(",", cells.Select(v =>
double.TryParse(v, System.Globalization.CultureInfo.InvariantCulture, out var n) ? n : 0));
else
properties.Remove("values");
}
if (properties.TryGetValue("categories", out var catRaw))
{
properties.Remove("categories"); // ChartHelper.AddSeries doesn't consume it
if (ChartHelper.IsRangeReference(catRaw))
{
categoriesRef = ChartHelper.NormalizeRangeReference(catRaw, sheetName);
cachedCats = ResolveRangeToCellValues(catRaw, sheetName);
}
}
var newIdx = ChartHelper.AddSeries(chartPart, properties);
if (newIdx == 0)
throw new ArgumentException(
"Cannot add a series: the chart has no existing series to derive structure from. Recreate the chart with the desired series instead.");
ChartHelper.ApplySeriesRangeRefs(chartPart, newIdx, valuesRef, categoriesRef, cachedCats);
return $"/{sheetName}/chart[{chartIdx}]/series[{newIdx}]";
}
private string AddDefault(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)
{
var index = position?.Index;
// Generic fallback: create typed element via SDK schema validation
// Parse parentPath: /<SheetName>/xmlPath...
var fbSegments = parentPath.TrimStart('/').Split('/', 2);
var fbSheetName = fbSegments[0];
var fbWorksheet = FindWorksheet(fbSheetName);
if (fbWorksheet == null)
throw new ArgumentException($"Sheet not found: {fbSheetName}");
OpenXmlElement fbParent = GetSheet(fbWorksheet);
if (fbSegments.Length > 1 && !string.IsNullOrEmpty(fbSegments[1]))View on GitHub (pinned to 1ced45e900)
Solutions
- Delete the empty chart and recreate it with at least one series via data= or dataRange=.
- Provide full series data at chart creation time instead of relying on append.
- Inspect the chart's plot area to confirm it has zero series before attempting append.
Example fix
// before (chart[1] exists but has 0 series) add /Sheet1/chart[1] --type chart-series --data "S1:1,2,3" // after (delete and recreate with initial series) remove /Sheet1/chart[1] add /Sheet1/chart --type chart --chartType bar --data "S1:1,2,3"
Defensive patterns
Strategy: try-catch
Validate before calling
// Inspect the chart's plot area for existing series before appending
var plotArea = chartPart.ChartSpace.PlotArea;
var hasSeries = plotArea.Descendants<DocumentFormat.OpenXml.Drawing.Charts.LineSeries>().Any()
|| plotArea.Descendants<DocumentFormat.OpenXml.Drawing.Charts.BarSeries>().Any()
|| plotArea.Descendants<DocumentFormat.OpenXml.Drawing.Charts.PieSeries>().Any();
if (!hasSeries)
throw new InvalidOperationException(
"Chart has no existing series. Recreate the chart with initial series data."); Try / catch
try { handler.AddChartSeries(parentPath, properties); }
catch (ArgumentException ex) when (ex.Message.Contains("no existing series to derive structure"))
{
Console.Error.WriteLine($"{ex.Message} Delete and recreate the chart.");
} Prevention
- Always create charts with at least one series so AddSeries has a template to clone.
- Avoid deleting all series from a chart; recreate instead.
- Inspect the plot area for existing series before attempting an append.
When it happens
Trigger: Calling add /Sheet/chart[N] --type chart-series on a standard chart that was created without any series (e.g. a chart created from an empty dataRange that was later partially repaired, or a chart whose series were all deleted). ChartHelper.AddSeries cannot find a base series and returns index 0.
Common situations: A chart was created with invalid or empty data and survived as a chart object with zero series. A prior operation deleted all series. The chart is structurally present but functionally empty.
Related errors
- dataRange resolved to 0 series columns: a single-column rang
- Chart requires a 'data' property. Use: data="Series1:1,2,3;S
- series must be added to a chart parent: /SheetName/chart[N]
- Sheet not found: {sheetName}
- Sheet has no drawings/charts
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/ea4590c924c62e36.
Report an issue: GitHub.