diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts index 3682d96512..e0de6d67de 100644 --- a/src/chart/line/LineView.ts +++ b/src/chart/line/LineView.ts @@ -345,6 +345,13 @@ function getVisualGradient( ? (outerColors[1] ? outerColors[1] : colorStops[stopLen - 1].color) : (outerColors[0] ? outerColors[0] : colorStops[0].color); } + if (!inRangeStopLen) { + // No color stops at all (e.g. when all visualMap pieces produce + // [-Infinity, Infinity] intervals, like `pieces: [{ lte: null }]`). + // Fall back to a single outer color or transparent so that we + // don't crash on `colorStopsInRange[0].coord` below. See #18066. + return outerColors[0] || outerColors[1] || 'transparent'; + } const tinyExtent = 10; // Arbitrary value: 10px const minCoord = colorStopsInRange[0].coord - tinyExtent; diff --git a/test/ut/spec/component/visualMap/setOption.test.ts b/test/ut/spec/component/visualMap/setOption.test.ts index d132385eac..d90da36a43 100755 --- a/test/ut/spec/component/visualMap/setOption.test.ts +++ b/test/ut/spec/component/visualMap/setOption.test.ts @@ -287,4 +287,30 @@ describe('vsiaulMap_setOption', function () { done(); }); + // See https://github.com/apache/echarts/issues/18066 + it('piecewiseWithNullBoundOnLineSeries', function (done) { + // Setting `lte: null` (or omitting both bounds) makes the piece + // interval [-Infinity, Infinity], which previously crashed + // line series rendering with + // "Cannot read properties of undefined (reading 'coord')". + expect(function () { + chart.setOption({ + xAxis: {type: 'category', data: ['A', 'B', 'C', 'D']}, + yAxis: {type: 'value'}, + visualMap: { + type: 'piecewise', + pieces: [ + // lte set to null should be treated as no upper bound. + {lte: null, color: 'red'} + ] + }, + series: [{ + type: 'line', + data: [10, 20, 30, 40] + }] + }); + }).not.toThrow(); + done(); + }); + }); \ No newline at end of file