forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortDemo.js
More file actions
55 lines (51 loc) · 1.58 KB
/
SortDemo.js
File metadata and controls
55 lines (51 loc) · 1.58 KB
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
import * as React from 'react';
import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { LineChart } from '@mui/x-charts/LineChart';
import { HighlightedCode } from '@mui/internal-core-docs/HighlightedCode';
const sortOptions = ['none', 'asc', 'desc'];
function getExample(sort) {
return `<LineChart
slotProps={{ tooltip: { trigger: 'axis', sort: '${sort}' } }}
{/* ... */}
/>`;
}
export default function SortDemo() {
const [sort, setSort] = React.useState('none');
return (
<Box sx={{ p: 2, width: 1, maxWidth: 600 }}>
<TextField
select
label="sort"
value={sort}
sx={{ minWidth: 200, mb: 2 }}
onChange={(event) => setSort(event.target.value)}
>
{sortOptions.map((option) => (
<MenuItem key={option} value={option}>
{option}
</MenuItem>
))}
</TextField>
<LineChart
xAxis={[
{
scaleType: 'point',
data: ['page A', 'page B', 'page C', 'page D', 'page E'],
},
]}
series={[
{ data: [2, 5, 3, 4, 1], label: 'Series x', showMark: true },
{ data: [5, 3, 1, null, 10], label: 'Series y', showMark: true },
{ data: [10, 4, 6, 2, 8], label: 'Series z', showMark: true },
]}
slotProps={{ tooltip: { trigger: 'axis', sort } }}
height={300}
hideLegend
margin={{ top: 20, right: 10 }}
/>
<HighlightedCode code={getExample(sort)} language="tsx" />
</Box>
);
}