Files
digital-data-react-mui-temp…/src/sections/overview/analytics-current-subject.tsx
2025-07-21 14:55:22 +02:00

74 lines
1.8 KiB
TypeScript

import type { CardProps } from '@mui/material/Card';
import type { ChartOptions } from 'src/components/chart';
import Card from '@mui/material/Card';
import Divider from '@mui/material/Divider';
import { useTheme } from '@mui/material/styles';
import CardHeader from '@mui/material/CardHeader';
import { Chart, useChart, ChartLegends } from 'src/components/chart';
// ----------------------------------------------------------------------
type Props = CardProps & {
title?: string;
subheader?: string;
chart: {
colors?: string[];
categories: string[];
series: {
name: string;
data: number[];
}[];
options?: ChartOptions;
};
};
export function AnalyticsCurrentSubject({ title, subheader, chart, sx, ...other }: Props) {
const theme = useTheme();
const chartColors = chart.colors ?? [
theme.palette.primary.main,
theme.palette.warning.main,
theme.palette.info.main,
];
const chartOptions = useChart({
colors: chartColors,
stroke: { width: 2 },
fill: { opacity: 0.48 },
xaxis: {
categories: chart.categories,
labels: { style: { colors: Array.from({ length: 6 }, () => theme.palette.text.secondary) } },
},
...chart.options,
});
return (
<Card sx={sx} {...other}>
<CardHeader title={title} subheader={subheader} />
<Chart
type="radar"
series={chart.series}
options={chartOptions}
slotProps={{ loading: { py: 2.5 } }}
sx={{
my: 1,
mx: 'auto',
width: 300,
height: 300,
}}
/>
<Divider sx={{ borderStyle: 'dashed' }} />
<ChartLegends
labels={chart.series.map((item) => item.name)}
colors={chartOptions?.colors}
sx={{ p: 3, justifyContent: 'center' }}
/>
</Card>
);
}