iOfficeAI/OfficeCLI · error · ArgumentException
Chart requires a 'data' property. Use: data="Series1:1,2,3;S
Error message
Chart requires a 'data' property. Use: data="Series1:1,2,3;Series2:4,5,6" or dataRange="Sheet1!A1:D5" or series1="Revenue:100,200,300"
What it means
Thrown when chart Add ends up with zero series and the user supplied neither a dataRange, a data= string, nor any seriesN= properties. This is the generic counterpart to error 520: the properties dictionary lacks every recognized series-input key, so seriesData is empty and no fallback data source exists.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Chart.cs:86
// a numCache/strCache so the chart renders before the workbook is
// re-evaluated (the HTML preview plots only from that cache).
// Resolve the ranges against the worksheet now to backfill the
// literal values, mirroring ParseDataRangeForChart.
BackfillSeriesRangeValues(ref seriesData, ref categories, chartSheetName, properties);
}
if (seriesData.Count == 0)
{
// A supplied-but-consumed dataRange must not get the generic
// "requires a data property" message: with a single-column range
// and no explicit categories=, the sole column is reserved as
// the category column, leaving zero series — say so.
if (properties.ContainsKey("dataRange") || properties.ContainsKey("datarange"))
throw new ArgumentException(
"dataRange resolved to 0 series columns: a single-column range is consumed as the " +
"category column by default. Pass categories= explicitly (e.g. categories=Sheet1!A1:A5) " +
"to plot that column as a series, or widen the dataRange to include a values column.");
throw new ArgumentException("Chart requires a 'data' property. Use: data=\"Series1:1,2,3;Series2:4,5,6\" " +
"or dataRange=\"Sheet1!A1:D5\" or series1=\"Revenue:100,200,300\"");
}
// Validate the chart type BEFORE any part is created: an unknown type
// used to throw inside the builder AFTER the DrawingsPart and its
// sheet relationship were attached, leaving an orphaned empty
// <xdr:wsDr/> part behind on every failed attempt. Extended (cx)
// types — funnel/treemap/… — route through ChartExBuilder below and
// must not be run through the classic-type parser.
if (!ChartExBuilder.IsExtendedChartType(chartType))
ChartHelper.ParseChartType(chartType);
// Create DrawingsPart if needed
var drawingsPart = chartWorksheet.DrawingsPart
?? chartWorksheet.AddNewPart<DrawingsPart>();
if (drawingsPart.WorksheetDrawing == null)
{View on GitHub (pinned to 1ced45e900)
Solutions
- Add a data= property with inline series: data="Series1:1,2,3;Series2:4,5,6".
- Add a dataRange= property pointing to a multi-column cell range: dataRange=Sheet1!A1:D5.
- Add one or more seriesN= properties: series1="Revenue:100,200,300".
- Verify the property key spelling matches exactly (data, dataRange, series1).
Example fix
// before add /Sheet1/chart --type chart --chartType bar --title "Sales" // after add /Sheet1/chart --type chart --chartType bar --title "Sales" --data "Revenue:100,200,300;Cost:50,60,70"
Defensive patterns
Strategy: validation
Validate before calling
// Ensure at least one series-data source is present
bool hasData = properties.ContainsKey("data");
bool hasRange = properties.ContainsKey("dataRange") || properties.ContainsKey("datarange");
bool hasSeries = properties.Keys.Any(k => System.Text.RegularExpressions.Regex.IsMatch(k, @"^series\d+$", RegexOptions.IgnoreCase));
if (!hasData && !hasRange && !hasSeries)
throw new InvalidOperationException(
"Chart requires a data source. Provide data=, dataRange=, or seriesN= properties."); Try / catch
try { handler.AddChart(parentPath, type, position, properties); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Chart requires a 'data' property"))
{
Console.Error.WriteLine(ex.Message);
} Prevention
- Always include data=, dataRange=, or at least one seriesN= property in every chart-add call.
- Build a pre-flight check that scans for recognized series-input keys.
- Use a typed chart-options builder that enforces at least one data source at compile time.
When it happens
Trigger: Calling chart Add with a chartType but none of: data, dataRange/datarange, series1, series2, etc. The inner if checks dataRange/datarange first; if that key is also absent, this generic message fires.
Common situations: User sets only cosmetic properties (title, type, anchor) and forgets the actual chart data. Also happens when property names are misspelled (e.g. 'data-set' instead of 'data') or when a script drops the data property conditionally.
Related errors
- dataRange resolved to 0 series columns: a single-column rang
- series must be added to a chart parent: /SheetName/chart[N]
- Sheet not found: {sheetName}
- Sheet has no drawings/charts
- Chart {chartIdx} not found (total: {excelCharts.Count})
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/1eae092a69208ac4.
Report an issue: GitHub.