p7/8 done
This commit is contained in:
49
labs/lab7/src/chart/components/GroupChart.tsx
Normal file
49
labs/lab7/src/chart/components/GroupChart.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { BarChart } from '@mui/x-charts/BarChart';
|
||||
import Container from '@mui/material/Container';
|
||||
import type { tGroup } from "../groupdata";
|
||||
import { useState } from 'react';
|
||||
import SettingChart from "./SettingChart";
|
||||
|
||||
type GroupProps = {
|
||||
data: tGroup;
|
||||
};
|
||||
|
||||
|
||||
function GroupChart({ data }: GroupProps) {
|
||||
const [series, setSeries] = useState({
|
||||
'Максимальная высота': true,
|
||||
'Средняя высота': false,
|
||||
'Минимальная высота': false,
|
||||
});
|
||||
let seriesY = Object.entries(series)
|
||||
.filter(item => item[1] == true)
|
||||
.map(item => {
|
||||
return {
|
||||
"dataKey": item[0], "label": item[0], barLabel: Object.entries(series)
|
||||
.filter(item => item[1] == true).length == 1 ? "value" : ""
|
||||
}
|
||||
});
|
||||
const chartSetting = {
|
||||
yAxis: [{ label: 'Высота (м)' }],
|
||||
height: 400,
|
||||
};
|
||||
|
||||
return (
|
||||
<Container maxWidth="lg">
|
||||
<BarChart
|
||||
dataset={data}
|
||||
xAxis={[{ scaleType: 'band', dataKey: 'Группа' }]}
|
||||
series={seriesY}
|
||||
slotProps={{
|
||||
legend: {
|
||||
position: { vertical: 'bottom', horizontal: 'center' },
|
||||
}
|
||||
}}
|
||||
{...chartSetting}
|
||||
/>
|
||||
<SettingChart series={series} setSeries={setSeries} />
|
||||
</Container>
|
||||
)
|
||||
};
|
||||
|
||||
export default GroupChart;
|
||||
Reference in New Issue
Block a user