-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add demo for styling charts with sx props (mui#12791)
Co-authored-by: alexandre <[email protected]>
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from 'react'; | ||
import { BarChart, barElementClasses } from '@mui/x-charts/BarChart'; | ||
import { axisClasses } from '@mui/x-charts/ChartsAxis'; | ||
|
||
const labels = ['Group A', 'Group B', 'Group C', 'Group D', 'Group E']; | ||
const lData = [42, 24, 56, 45, 3]; | ||
const rData = [57, 7, 19, 16, 22]; | ||
const colors = ['#006BD6', '#EC407A']; | ||
|
||
export default function SxStyling() { | ||
return ( | ||
<BarChart | ||
sx={(theme) => ({ | ||
[`.${barElementClasses.root}`]: { | ||
fill: theme.palette.background.paper, | ||
strokeWidth: 2, | ||
}, | ||
[`.MuiBarElement-series-l_id`]: { | ||
stroke: colors[0], | ||
}, | ||
[`.MuiBarElement-series-r_id`]: { | ||
stroke: colors[1], | ||
}, | ||
[`.${axisClasses.root}`]: { | ||
[`.${axisClasses.tick}, .${axisClasses.line}`]: { | ||
stroke: '#006BD6', | ||
strokeWidth: 3, | ||
}, | ||
[`.${axisClasses.tickLabel}`]: { | ||
fill: '#006BD6', | ||
}, | ||
}, | ||
border: `1px solid rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1)`, | ||
backgroundImage: `linear-gradient(rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px)`, | ||
backgroundSize: '35px 35px', | ||
backgroundPosition: '20px 20px, 20px 20px', | ||
})} | ||
xAxis={[{ scaleType: 'band', data: labels }]} | ||
series={[ | ||
{ data: lData, label: 'l', id: 'l_id' }, | ||
{ data: rData, label: 'r', id: 'r_id' }, | ||
]} | ||
colors={colors} | ||
width={500} | ||
height={300} | ||
/> | ||
); | ||
} |
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,49 @@ | ||
import * as React from 'react'; | ||
import { BarChart, barElementClasses } from '@mui/x-charts/BarChart'; | ||
import { axisClasses } from '@mui/x-charts/ChartsAxis'; | ||
|
||
const labels: string[] = ['Group A', 'Group B', 'Group C', 'Group D', 'Group E']; | ||
const lData: number[] = [42, 24, 56, 45, 3]; | ||
const rData: number[] = [57, 7, 19, 16, 22]; | ||
const colors: string[] = ['#006BD6', '#EC407A']; | ||
|
||
export default function SxStyling(): React.JSX.Element { | ||
return ( | ||
<BarChart | ||
sx={(theme) => ({ | ||
[`.${barElementClasses.root}`]: { | ||
fill: theme.palette.background.paper, | ||
strokeWidth: 2, | ||
}, | ||
[`.MuiBarElement-series-l_id`]: { | ||
stroke: colors[0], | ||
}, | ||
[`.MuiBarElement-series-r_id`]: { | ||
stroke: colors[1], | ||
}, | ||
[`.${axisClasses.root}`]: { | ||
[`.${axisClasses.tick}, .${axisClasses.line}`]: { | ||
stroke: '#006BD6', | ||
strokeWidth: 3, | ||
}, | ||
[`.${axisClasses.tickLabel}`]: { | ||
fill: '#006BD6', | ||
}, | ||
}, | ||
|
||
border: `1px solid rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1)`, | ||
backgroundImage: `linear-gradient(rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px)`, | ||
backgroundSize: '35px 35px', | ||
backgroundPosition: '20px 20px, 20px 20px', | ||
})} | ||
xAxis={[{ scaleType: 'band', data: labels }]} | ||
series={[ | ||
{ data: lData, label: 'l', id: 'l_id' }, | ||
{ data: rData, label: 'r', id: 'r_id' }, | ||
]} | ||
colors={colors} | ||
width={500} | ||
height={300} | ||
/> | ||
); | ||
} |
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