p8/8 done lab7 done

This commit is contained in:
2026-04-15 00:11:27 +10:00
parent 0a71925410
commit e6daea7cda
2 changed files with 88 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
import { BarChart } from '@mui/x-charts/BarChart'; import { BarChart } from '@mui/x-charts/BarChart';
import { LineChart } from '@mui/x-charts/LineChart';
import Container from '@mui/material/Container'; import Container from '@mui/material/Container';
import type { tGroup } from "../groupdata"; import type { tGroup } from "../groupdata";
import { useState } from 'react'; import { useState } from 'react';
@@ -10,6 +11,7 @@ type GroupProps = {
function GroupChart({ data }: GroupProps) { function GroupChart({ data }: GroupProps) {
const [isBar, setIsBar] = useState(true);
const [series, setSeries] = useState({ const [series, setSeries] = useState({
'Максимальная высота': true, 'Максимальная высота': true,
'Средняя высота': false, 'Средняя высота': false,
@@ -30,7 +32,7 @@ function GroupChart({ data }: GroupProps) {
return ( return (
<Container maxWidth="lg"> <Container maxWidth="lg">
<BarChart {isBar && <BarChart
dataset={data} dataset={data}
xAxis={[{ scaleType: 'band', dataKey: 'Группа' }]} xAxis={[{ scaleType: 'band', dataKey: 'Группа' }]}
series={seriesY} series={seriesY}
@@ -40,8 +42,19 @@ function GroupChart({ data }: GroupProps) {
} }
}} }}
{...chartSetting} {...chartSetting}
/> />}
<SettingChart series={series} setSeries={setSeries} /> {!isBar &&<LineChart
dataset={data}
xAxis={[{ scaleType: 'band', dataKey: 'Группа' }]}
series={seriesY}
slotProps={{
legend: {
position: { vertical: 'bottom', horizontal: 'center' },
},
}}
{...chartSetting}
/>}
<SettingChart series={series} setSeries={setSeries} isBar={isBar} setIsBar={setIsBar} />
</Container> </Container>
) )
}; };

View File

@@ -2,6 +2,12 @@ import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel'; import FormLabel from '@mui/material/FormLabel';
import FormControlLabel from '@mui/material/FormControlLabel'; import FormControlLabel from '@mui/material/FormControlLabel';
import Checkbox from '@mui/material/Checkbox'; import Checkbox from '@mui/material/Checkbox';
import Stack from '@mui/material/Stack';
import Divider from '@mui/material/Divider';
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import Container from '@mui/material/Container';
type tSeries = { type tSeries = {
'Максимальная высота': boolean, 'Максимальная высота': boolean,
'Средняя высота': boolean, 'Средняя высота': boolean,
@@ -9,19 +15,51 @@ type tSeries = {
} }
type CheckboxProps = { type CheckboxProps = {
series: tSeries; series: tSeries;
setSeries: React.Dispatch< setSeries: React.Dispatch<React.SetStateAction<tSeries>>;
React.SetStateAction<tSeries> isBar: boolean;
>; setIsBar: React.Dispatch<React.SetStateAction<boolean>>
}; };
function SettingChart({ series, setSeries }: CheckboxProps) { function SettingChart({ series, setSeries, isBar, setIsBar }: CheckboxProps) {
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSeries({ setSeries({
...series, ...series,
[event.target.name]: event.target.checked, [event.target.name]: event.target.checked,
}); });
}; };
const handleRadioButtonChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setIsBar(event.target.value === "bar");
};
return ( return (
<Stack
direction="row"
divider={<Divider orientation="vertical" flexItem />}
spacing={2}
sx={{ m: "20px 0", justifyContent: "center", }}
>
<FormControl>
<FormLabel id="label-radio-group">
Тип диаграммы:
</FormLabel>
<RadioGroup
name="group-radio"
value={(isBar) ? "bar" : "dot"}
>
<FormControlLabel value="bar"
control={
<Radio checked={isBar} onChange={handleRadioButtonChange} />
}
label="Гистограмма"
/>
<FormControlLabel value="dot"
control={
<Radio checked={!isBar} onChange={handleRadioButtonChange} />
}
label="Линейная"
/>
</RadioGroup>
</FormControl>
<FormControl> <FormControl>
<FormLabel id="label-checkbox-group"> <FormLabel id="label-checkbox-group">
На диаграмме показать: На диаграмме показать:
@@ -51,6 +89,7 @@ function SettingChart({ series, setSeries }: CheckboxProps) {
label="минимальную высоту" label="минимальную высоту"
/> />
</FormControl> </FormControl>
</Stack>
) )
} }
export default SettingChart; export default SettingChart;