-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Add
onClick
support (#11411)
Signed-off-by: Alexandre Fauquette <[email protected]>
- Loading branch information
1 parent
5db3711
commit 9d35151
Showing
60 changed files
with
1,243 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import UndoOutlinedIcon from '@mui/icons-material/UndoOutlined'; | ||
|
||
import { BarChart } from '@mui/x-charts/BarChart'; | ||
|
||
import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; | ||
|
||
const barChartsParams = { | ||
series: [ | ||
{ | ||
id: 'series-1', | ||
data: [3, 4, 1, 6, 5], | ||
label: 'A', | ||
stack: 'total', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
{ | ||
id: 'series-2', | ||
data: [4, 3, 1, 5, 8], | ||
label: 'B', | ||
stack: 'total', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
{ | ||
id: 'series-3', | ||
data: [4, 2, 5, 4, 1], | ||
label: 'C', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
], | ||
xAxis: [{ data: ['0', '3', '6', '9', '12'], scaleType: 'band', id: 'axis1' }], | ||
height: 400, | ||
}; | ||
|
||
export default function BarClickNoSnap() { | ||
const [itemData, setItemData] = React.useState(); | ||
const [axisData, setAxisData] = React.useState(); | ||
|
||
return ( | ||
<Stack | ||
direction={{ xs: 'column', md: 'row' }} | ||
spacing={{ xs: 0, md: 4 }} | ||
sx={{ width: '100%' }} | ||
> | ||
<Box sx={{ flexGrow: 1 }}> | ||
<BarChart | ||
{...barChartsParams} | ||
onItemClick={(event, d) => setItemData(d)} | ||
onAxisClick={(event, d) => setAxisData(d)} | ||
/> | ||
</Box> | ||
|
||
<Stack direction="column" sx={{ width: { xs: '100%', md: '40%' } }}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography>Click on the chart</Typography> | ||
<IconButton | ||
aria-label="reset" | ||
size="small" | ||
onClick={() => { | ||
setItemData(null); | ||
setAxisData(null); | ||
}} | ||
> | ||
<UndoOutlinedIcon fontSize="small" /> | ||
</IconButton> | ||
</Box> | ||
<HighlightedCode | ||
code={`// Data from item click | ||
${itemData ? JSON.stringify(itemData, null, 2) : '// The data will appear here'} | ||
// Data from axis click | ||
${axisData ? JSON.stringify(axisData, null, 2) : '// The data will appear here'} | ||
`} | ||
language="json" | ||
copyButtonHidden | ||
/> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import * as React from 'react'; | ||
import Stack from '@mui/material/Stack'; | ||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import UndoOutlinedIcon from '@mui/icons-material/UndoOutlined'; | ||
|
||
import { LineChart } from '@mui/x-charts/LineChart'; | ||
|
||
import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; | ||
|
||
const lineChartsParams = { | ||
series: [ | ||
{ | ||
id: 'series-1', | ||
data: [3, 4, 1, 6, 5], | ||
label: 'A', | ||
area: true, | ||
stack: 'total', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
{ | ||
id: 'series-2', | ||
data: [4, 3, 1, 5, 8], | ||
label: 'B', | ||
area: true, | ||
stack: 'total', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
{ | ||
id: 'series-3', | ||
data: [4, 2, 5, 4, 1], | ||
label: 'C', | ||
area: true, | ||
stack: 'total', | ||
highlightScope: { | ||
highlighted: 'item', | ||
}, | ||
}, | ||
], | ||
xAxis: [{ data: [0, 3, 6, 9, 12], scaleType: 'linear', id: 'axis1' }], | ||
height: 400, | ||
}; | ||
|
||
export default function LineClickNoSnap() { | ||
const [itemData, setItemData] = React.useState(); | ||
const [axisData, setAxisData] = React.useState(); | ||
|
||
return ( | ||
<Stack | ||
direction={{ xs: 'column', md: 'row' }} | ||
spacing={{ xs: 0, md: 4 }} | ||
sx={{ width: '100%' }} | ||
> | ||
<Box sx={{ flexGrow: 1 }}> | ||
<LineChart | ||
{...lineChartsParams} | ||
onAreaClick={(event, d) => setItemData(d)} | ||
onMarkClick={(event, d) => setItemData(d)} | ||
onLineClick={(event, d) => setItemData(d)} | ||
onAxisClick={(event, d) => setAxisData(d)} | ||
/> | ||
</Box> | ||
|
||
<Stack direction="column" sx={{ width: { xs: '100%', md: '40%' } }}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography>Click on the chart</Typography> | ||
<IconButton | ||
aria-label="reset" | ||
size="small" | ||
onClick={() => { | ||
setItemData(null); | ||
setAxisData(null); | ||
}} | ||
> | ||
<UndoOutlinedIcon fontSize="small" /> | ||
</IconButton> | ||
</Box> | ||
<HighlightedCode | ||
code={`// Data from item click | ||
${itemData ? JSON.stringify(itemData, null, 2) : '// The data will appear here'} | ||
// Data from axis click | ||
${axisData ? JSON.stringify(axisData, null, 2) : '// The data will appear here'} | ||
`} | ||
language="json" | ||
copyButtonHidden | ||
/> | ||
</Stack> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.