Skip to content

Commit

Permalink
[charts] Fix empty series pie chart v7 (#16657)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobelchior authored Feb 20, 2025
1 parent 3fe239a commit 3f23a9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/x-charts/src/PieChart/PieChart.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { createRenderer } from '@mui/internal-test-utils/createRenderer';
import { createRenderer, screen } from '@mui/internal-test-utils/createRenderer';
import { describeConformance } from 'test/utils/describeConformance';
import { PieChart } from '@mui/x-charts/PieChart';
import { expect } from 'chai';

describe('<PieChart />', () => {
const { render } = createRenderer();
Expand Down Expand Up @@ -37,4 +38,11 @@ describe('<PieChart />', () => {
],
}),
);

it('should render "No Data" overlay when series prop is an empty array', () => {
render(<PieChart height={100} width={100} series={[]} />);

const noDataOverlay = screen.getByText('No data to display');
expect(noDataOverlay).toBeVisible();
});
});
2 changes: 1 addition & 1 deletion packages/x-charts/src/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const PieChart = React.forwardRef(function PieChart(inProps: PieChartProps, ref)
{
id: DEFAULT_X_AXIS_KEY,
scaleType: 'point',
data: [...new Array(Math.max(...series.map((s) => s.data.length)))].map(
data: [...new Array(Math.max(0, ...series.map((s) => s.data.length)))].map(
(_, index) => index,
),
},
Expand Down

0 comments on commit 3f23a9e

Please # to comment.