apache/echarts · error
Invalid coords {}. Lines must have 2d coords array in data i
Error message
Invalid coords {}. Lines must have 2d coords array in data item. What it means
DEV-only guard in LinesSeries._getCoordsFromItemModel: a 'lines' series data item must provide coords as a 2D array (an array of [x,y] pairs), because each data item may itself contain multiple polyline segments. The check verifies coords is an Array, non-empty, and coords[0] is itself an Array. Stripped in production.
Source
Thrown at src/chart/lines/LinesSeries.ts:217
}
else {
this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
}
params.data = new Float32Array(result.count);
}
this.getRawData().appendData(params.data);
}
_getCoordsFromItemModel(idx: number) {
const itemModel = this.getData().getItemModel<LinesDataItemOption>(idx);
const coords = (itemModel.option instanceof Array)
? itemModel.option : itemModel.getShallow('coords');
if (__DEV__) {
if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
throw new Error(
'Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.'
);
}
}
return coords;
}
getLineCoordsCount(idx: number) {
if (this._flatCoordsOffset) {
return this._flatCoordsOffset[idx * 2 + 1];
}
else {
return this._getCoordsFromItemModel(idx).length;
}
}
getLineCoords(idx: number, out: number[][]) {
if (this._flatCoordsOffset) {View on GitHub (pinned to 30076aedcd)
Solutions
- Provide coords as [[x1,y1],[x2,y2],...]
- Or pass the data item itself as a 2D array
- Validate the data shape before setOption
Example fix
// before
{ type: 'lines', data: [{ coords: [116, 39] }] }
// after
{ type: 'lines', data: [{ coords: [[116, 39], [121, 31]] }] } Defensive patterns
Strategy: validation
Validate before calling
(option.series || []).filter((s: any) => s.type === 'lines').forEach((s: any) => {
(s.data || []).forEach((d: any) => {
const c = Array.isArray(d) ? d : d && d.coords;
if (!(Array.isArray(c) && c.length > 0 && Array.isArray(c[0]))) {
console.error('[lines] data item has invalid coords', d);
}
});
}); Type guard
const is2DCoords = (c: unknown): c is number[][] => Array.isArray(c) && c.length > 0 && Array.isArray(c[0]);
Prevention
- Treat each lines data item's coords as number[][]
- Validate the data shape before setOption
- Distinguish the 'lines' series shape from the regular 'line' series
When it happens
Trigger: Passing a data item like { coords: [116, 39] } (flat pair), { coords: 'foo' }, omitting coords, or supplying a 1D array of numbers.
Common situations: Confusing the 'lines' series data shape with the regular 'line' series; data export that flattened nested arrays; truncating coords during serialization.
Related errors
- Invalid data format.
- Unknown coordinate system {}
- key must not be "{}"
- Heatmap must use with visualMap
- Heatmap on cartesian must have two category axes
AI-assisted analysis of apache/echarts@30076aedcd (2026-08-12).
Data as JSON: /api/errors/df395771af90fc16.
Report an issue: GitHub.