-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathZoomControlled.tsx
79 lines (74 loc) · 1.7 KB
/
ZoomControlled.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as React from 'react';
import { LineChartPro } from '@mui/x-charts-pro/LineChartPro';
import Button from '@mui/material/Button';
import Stack from '@mui/material/Stack';
import { ZoomData } from '@mui/x-charts-pro/models';
import { BarChartPro } from '@mui/x-charts-pro/BarChartPro';
import { randomData } from './randomData';
const lineAxis = [
{
zoom: true,
scaleType: 'point' as const,
id: 'shared-x-axis',
data: randomData.map((v, i) => i),
},
];
const barAxis = [
{
zoom: true,
scaleType: 'band' as const,
id: 'shared-x-axis',
data: randomData.map((v, i) => i),
},
];
const initialZoomData: ZoomData[] = [
{
axisId: 'shared-x-axis',
start: 20,
end: 40,
},
];
export default function ZoomControlled() {
const [zoomData, setZoomData] = React.useState(initialZoomData);
return (
<Stack sx={{ width: '100%', justifyContent: 'flex-start' }}>
<LineChartPro
{...chartProps}
onZoomChange={setZoomData}
zoomData={zoomData}
xAxis={lineAxis}
/>
<BarChartPro
{...chartProps}
onZoomChange={setZoomData}
zoomData={zoomData}
xAxis={barAxis}
/>
<pre>{JSON.stringify(zoomData, null, 2)}</pre>
<div>
<Button
variant="contained"
onClick={() =>
setZoomData([{ axisId: 'shared-x-axis', start: 0, end: 100 }])
}
>
Reset zoom
</Button>
</div>
</Stack>
);
}
const chartProps = {
height: 300,
sx: { width: '100%' },
series: [
{
label: 'Series A',
data: randomData.map((v) => v.y1),
},
{
label: 'Series B',
data: randomData.map((v) => v.y2),
},
],
};