diff --git a/packages/f2/src/components/line/withLine.tsx b/packages/f2/src/components/line/withLine.tsx index 51abc2c14..bf31a41df 100644 --- a/packages/f2/src/components/line/withLine.tsx +++ b/packages/f2/src/components/line/withLine.tsx @@ -29,7 +29,11 @@ export default (View) => { const tmpPoints = []; for (let i = 0, len = points.length; i < len; i++) { const point = points[i]; - const { y } = point; + const { x, y } = point; + // 过滤 x 为 NaN 的点 + if (isNaN(x)) { + continue; + } if (isArray(y)) { if (isNaN(y[0])) { continue; @@ -51,7 +55,11 @@ export default (View) => { let tmpPoints = []; for (let i = 0, len = points.length; i < len; i++) { const point = points[i]; - const { y } = point; + const { x, y } = point; + // 过滤 x 为 NaN 的点 + if (isNaN(x)) { + continue; + } if (isArray(y)) { if (isNaN(y[0])) { if (tmpPoints.length) { diff --git a/packages/f2/test/issues/1867.test.tsx b/packages/f2/test/issues/1867.test.tsx new file mode 100644 index 000000000..2241ce78c --- /dev/null +++ b/packages/f2/test/issues/1867.test.tsx @@ -0,0 +1,66 @@ +import { jsx, Canvas, Chart, Axis, Area } from '../../src'; +import { createContext, delay } from '../util'; + +const data = [ + { + dt: '20231008', + date: '10-08', + value: 1.31, + }, + { + dt: '20231009', + date: '10-09', + value: 57.5, + }, + { + dt: '20231010', + // date: '10-10', + value: 151.83, + }, + { + dt: '20231011', + date: '10-11', + value: 291.6, + }, + { + dt: '20231012', + date: '10-12', + value: 45.62, + }, + { + dt: '20231013', + date: '10-13', + value: 7.4, + }, + { + dt: '20231007', + // data: '10-07', + value: 9, + }, +]; + +describe('x 轴字段不存在', () => { + it('x 轴字段不存在', async () => { + const context = createContext(); + const { props } = ( + + + + + + + ); + + const canvas = new Canvas(props); + canvas.render(); + + await delay(1000); + + expect(context).toMatchImageSnapshot(); + }); +}); diff --git "a/packages/f2/test/issues/__image_snapshots__/1867-test-tsx-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-1-snap.png" "b/packages/f2/test/issues/__image_snapshots__/1867-test-tsx-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-1-snap.png" new file mode 100644 index 000000000..f8dcf5dd4 Binary files /dev/null and "b/packages/f2/test/issues/__image_snapshots__/1867-test-tsx-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-x-\350\275\264\345\255\227\346\256\265\344\270\215\345\255\230\345\234\250-1-snap.png" differ