diff --git a/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx b/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx
index 6a0810ce8dd3..354d06465b4b 100644
--- a/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx
+++ b/packages/x-charts/src/ScatterChart/ScatterChart.test.tsx
@@ -1,5 +1,6 @@
import * as React from 'react';
-import { createRenderer } from '@mui/internal-test-utils/createRenderer';
+import { expect } from 'chai';
+import { createRenderer, screen } from '@mui/internal-test-utils/createRenderer';
import { describeConformance } from 'test/utils/describeConformance';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
@@ -38,4 +39,54 @@ describe('', () => {
],
}),
);
+
+ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+
+ it('should support dataset with missing values', async function test() {
+ if (isJSDOM) {
+ this.skip();
+ }
+
+ // x from 500 to 600
+ // y from 100 to 200
+ const dataset = [
+ {
+ version: 'data-0',
+ a1: 500,
+ a2: 100,
+ },
+ {
+ version: 'data-1',
+ a1: 600,
+ a2: 200,
+ },
+ {
+ version: 'data-2',
+ // Item with missing x-values
+ // a1: 500,
+ a2: 200,
+ },
+ {
+ version: 'data-2',
+ // Item with missing y-values
+ a1: 500,
+ // a2: 200,
+ },
+ ];
+
+ render(
+ ,
+ );
+
+ const labelX = await screen.findByText('100');
+ expect(labelX).toBeVisible();
+
+ const labelY = await screen.findByText('600');
+ expect(labelY).toBeVisible();
+ });
});
diff --git a/packages/x-charts/src/ScatterChart/extremums.ts b/packages/x-charts/src/ScatterChart/extremums.ts
index 806295a1997f..3e739e90eb42 100644
--- a/packages/x-charts/src/ScatterChart/extremums.ts
+++ b/packages/x-charts/src/ScatterChart/extremums.ts
@@ -6,9 +6,10 @@ import {
const mergeMinMax = (
acc: ExtremumGetterResult,
val: ExtremumGetterResult,
-): ExtremumGetterResult => {
- return [Math.min(acc[0], val[0]), Math.max(acc[1], val[1])];
-};
+): ExtremumGetterResult => [
+ val[0] === null ? acc[0] : Math.min(acc[0], val[0]),
+ val[1] === null ? acc[1] : Math.max(acc[1], val[1]),
+];
export const getExtremumX: ExtremumGetter<'scatter'> = (params) => {
const { series, axis, isDefaultAxis, getFilters } = params;
diff --git a/packages/x-charts/src/ScatterChart/formatter.ts b/packages/x-charts/src/ScatterChart/formatter.ts
index 60c024f88c2e..fa55ee74a6b9 100644
--- a/packages/x-charts/src/ScatterChart/formatter.ts
+++ b/packages/x-charts/src/ScatterChart/formatter.ts
@@ -23,8 +23,8 @@ const formatter: SeriesFormatter<'scatter'> = ({ series, seriesOrder }, dataset)
? (seriesData.data ?? [])
: (dataset?.map((d) => {
return {
- x: d[datasetKeys.x],
- y: d[datasetKeys.y],
+ x: d[datasetKeys.x] ?? null,
+ y: d[datasetKeys.y] ?? null,
z: datasetKeys.z && d[datasetKeys.z],
id: d[datasetKeys.id],
} as ScatterValueType;