-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[charts] Add population pyramid demo #17652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[charts] Add population pyramid demo #17652
Conversation
Thanks for adding a type label to the PR! 👍 |
6d17265
to
a060d50
Compare
Deploy preview: https://deploy-preview-17652--material-ui-x.netlify.app/ Updated pages: |
CodSpeed Performance ReportMerging #17652 will not alter performanceComparing Summary
|
import { BarChart } from '@mui/x-charts/BarChart'; | ||
import { Stack, Typography } from '@mui/material'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { BarChart } from '@mui/x-charts/BarChart'; | |
import { Stack, Typography } from '@mui/material'; | |
import Stack from '@mui/material/Stack'; | |
import Typography from '@mui/material/Typography'; | |
import { BarChart } from '@mui/x-charts/BarChart'; |
]} | ||
xAxis={[ | ||
{ | ||
valueFormatter: (d: number) => `${numberFormatter.format(Math.abs(d))}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the axis will be easier to read
valueFormatter: (d: number) => `${numberFormatter.format(Math.abs(d))}`, | |
valueFormatter: (d: number) => `${numberFormatter.format(Math.abs(d) / 1000 )}k`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const suffixes = [ | ||
{ value: 1e6, symbol: 'M' }, | ||
{ value: 1e3, symbol: 'k' }, | ||
]; | ||
|
||
const suffix = suffixes.find((s) => Math.abs(number) >= s.value); | ||
|
||
if (!suffix) { | ||
return new Intl.NumberFormat('en-US').format(number); | ||
} | ||
|
||
const formattedValue = new Intl.NumberFormat('en-US', { | ||
minimumFractionDigits: 0, | ||
maximumFractionDigits: 1, | ||
}).format(number / suffix.value); | ||
|
||
return formattedValue + suffix.symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get it with less effort ;)
const suffixes = [ | |
{ value: 1e6, symbol: 'M' }, | |
{ value: 1e3, symbol: 'k' }, | |
]; | |
const suffix = suffixes.find((s) => Math.abs(number) >= s.value); | |
if (!suffix) { | |
return new Intl.NumberFormat('en-US').format(number); | |
} | |
const formattedValue = new Intl.NumberFormat('en-US', { | |
minimumFractionDigits: 0, | |
maximumFractionDigits: 1, | |
}).format(number / suffix.value); | |
return formattedValue + suffix.symbol; | |
return new Intl.NumberFormat('en-US', { notation: 'compact' }).format(number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, thank you 😄
Add a population pyramid demo with data for South Korea in 2022.
Data source: KOSIS.