apache/echarts · error

Invalid data format.

Error message

Invalid data format.

What it means

DEV-only guard in the LinesSeries flat-coords decoding loop: when a 'lines' series is supplied with flat coordinate data (a flat number array plus a parallel offset/length table), the decoder walks the buffer per segment; if the cursor i runs past len mid-segment the data is malformed and it throws. Stripped in production.

Source

Thrown at src/chart/lines/LinesSeries.ts:286

            let coordsCursor = 0;
            let offsetCursor = 0;
            let dataCount = 0;
            for (let i = 0; i < len;) {
                dataCount++;
                const count = data[i++] as number;
                // Offset
                coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
                // Len
                coordsOffsetAndLenStorage[offsetCursor++] = count;
                for (let k = 0; k < count; k++) {
                    const x = data[i++] as number;
                    const y = data[i++] as number;
                    coordsStorage[coordsCursor++] = x;
                    coordsStorage[coordsCursor++] = y;

                    if (i > len) {
                        if (__DEV__) {
                            throw new Error('Invalid data format.');
                        }
                    }
                }
            }

            return {
                flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
                flatCoords: coordsStorage,
                count: dataCount
            };
        }

        return {
            flatCoordsOffset: null,
            flatCoords: null,
            count: data.length
        };
    }

View on GitHub (pinned to 30076aedcd)

Solutions

  1. Prefer nested coords (number[][]) which is independently validated by error [7]
  2. If using flat data, ensure each segment's count matches the number of x,y pairs present
  3. Re-encode flat data with a vetted helper rather than building it by hand

Example fix

// before (flat, truncated / odd count)
{ type: 'lines', data: [{ coords: [116, 39, 121] }] } // 3 numbers

// after (nested, validated)
{ type: 'lines', data: [{ coords: [[116, 39], [121, 31]] }] }
Defensive patterns

Strategy: validation

Validate before calling

function validFlat(data: number[]): boolean {
  return Array.isArray(data) && data.length % 2 === 0;
}

Prevention

When it happens

Trigger: Supplying flat (non-nested) coords data whose offset table claims more points than the buffer actually holds; corrupt or truncated flat arrays; odd-length coordinate buffers.

Common situations: Hand-rolled flat-encoding of lines data; serializer that dropped trailing numbers; mismatched coords/offsets tables.

Related errors


AI-assisted analysis of apache/echarts@30076aedcd (2026-08-12). Data as JSON: /api/errors/b4adbf83d8551c17. Report an issue: GitHub.