-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[charts] Apply axis colorMap to radial bar fill #22800
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
Merged
+139
−1
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad3b494
[charts] Apply axis colorMap to radial bar fill
JCQuintas 33a8210
ci: retrigger static
JCQuintas bfd0cfc
Merge branch 'master' into feat/radial-bar-colormap
JCQuintas 3788526
improve
JCQuintas a2196f3
doc suggestion
JCQuintas 95c86b4
Merge branch 'master' into feat/radial-bar-colormap
JCQuintas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,63 @@ | ||
| import * as React from 'react'; | ||
| import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart'; | ||
|
|
||
| const healthData = [ | ||
| { metric: 'Water', value: 5, goal: 8, color: '#00bcd4' }, | ||
| { metric: 'Sleep', value: 6.5, goal: 8, color: '#3f51b5' }, | ||
| { metric: 'Calories', value: 540, goal: 700, color: '#ff9800' }, | ||
| { metric: 'Activity', value: 42, goal: 60, color: '#4caf50' }, | ||
| { metric: 'Steps', value: 8200, goal: 10000, color: '#e91e63' }, | ||
| ]; | ||
|
|
||
| const dataset = healthData.map((d) => ({ | ||
| metric: d.metric, | ||
| progress: Math.round((d.value / d.goal) * 100), | ||
| })); | ||
|
|
||
| const highlightScope = { highlight: 'none', fade: 'none' }; | ||
|
|
||
| export default function HealthRadialBarChart() { | ||
| return ( | ||
| <RadialBarChart | ||
| height={400} | ||
| dataset={dataset} | ||
| series={[ | ||
| { | ||
| dataKey: 'progress', | ||
| layout: 'horizontal', | ||
| label: 'Progress', | ||
| highlightScope, | ||
| valueFormatter: (value) => `${value}%`, | ||
| }, | ||
| ]} | ||
| radiusAxis={[ | ||
| { | ||
| scaleType: 'band', | ||
| dataKey: 'metric', | ||
| categoryGapRatio: 0.3, | ||
| disableLine: true, | ||
| disableTicks: true, | ||
| colorMap: { | ||
| type: 'ordinal', | ||
| values: healthData.map((d) => d.metric), | ||
| colors: healthData.map((d) => d.color), | ||
| }, | ||
| }, | ||
| ]} | ||
| rotationAxis={[ | ||
| { | ||
| scaleType: 'linear', | ||
| disableTickLabel: true, | ||
| disableLine: true, | ||
| disableTicks: true, | ||
| min: 0, | ||
| max: 100, | ||
| valueFormatter: (value) => `${value}%`, | ||
| }, | ||
| ]} | ||
| axisHighlight={{ rotation: 'none', radius: 'none' }} | ||
| hideLegend | ||
| slotProps={{ tooltip: { trigger: 'none' } }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or 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,63 @@ | ||
| import * as React from 'react'; | ||
| import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart'; | ||
|
|
||
| const healthData = [ | ||
| { metric: 'Water', value: 5, goal: 8, color: '#00bcd4' }, | ||
| { metric: 'Sleep', value: 6.5, goal: 8, color: '#3f51b5' }, | ||
| { metric: 'Calories', value: 540, goal: 700, color: '#ff9800' }, | ||
| { metric: 'Activity', value: 42, goal: 60, color: '#4caf50' }, | ||
| { metric: 'Steps', value: 8200, goal: 10000, color: '#e91e63' }, | ||
| ]; | ||
|
|
||
| const dataset = healthData.map((d) => ({ | ||
| metric: d.metric, | ||
| progress: Math.round((d.value / d.goal) * 100), | ||
| })); | ||
|
|
||
| const highlightScope = { highlight: 'none', fade: 'none' } as const; | ||
|
|
||
| export default function HealthRadialBarChart() { | ||
| return ( | ||
| <RadialBarChart | ||
| height={400} | ||
| dataset={dataset} | ||
| series={[ | ||
| { | ||
| dataKey: 'progress', | ||
| layout: 'horizontal', | ||
| label: 'Progress', | ||
| highlightScope, | ||
| valueFormatter: (value) => `${value}%`, | ||
| }, | ||
| ]} | ||
| radiusAxis={[ | ||
| { | ||
| scaleType: 'band', | ||
| dataKey: 'metric', | ||
| categoryGapRatio: 0.3, | ||
| disableLine: true, | ||
| disableTicks: true, | ||
| colorMap: { | ||
| type: 'ordinal', | ||
| values: healthData.map((d) => d.metric), | ||
| colors: healthData.map((d) => d.color), | ||
| }, | ||
| }, | ||
| ]} | ||
| rotationAxis={[ | ||
| { | ||
| scaleType: 'linear', | ||
| disableTickLabel: true, | ||
| disableLine: true, | ||
| disableTicks: true, | ||
| min: 0, | ||
| max: 100, | ||
| valueFormatter: (value) => `${value}%`, | ||
| }, | ||
| ]} | ||
| axisHighlight={{ rotation: 'none', radius: 'none' }} | ||
| hideLegend | ||
| slotProps={{ tooltip: { trigger: 'none' } }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This section of the docs let me think only the band axis can have a color map
Might be better to link to the bar charts docs section about colorMap saying that x/y axes are replaced by rotation/radius
https://mui.com/x/react-charts/bars/#color-scale