|
| 1 | +import * as React from 'react'; |
| 2 | +import { RadialBarChart } from '@mui/x-charts-premium/RadialBarChart'; |
| 3 | + |
| 4 | +const healthData = [ |
| 5 | + { metric: 'Water', value: 5, goal: 8, color: '#00bcd4' }, |
| 6 | + { metric: 'Sleep', value: 6.5, goal: 8, color: '#3f51b5' }, |
| 7 | + { metric: 'Calories', value: 540, goal: 700, color: '#ff9800' }, |
| 8 | + { metric: 'Activity', value: 42, goal: 60, color: '#4caf50' }, |
| 9 | + { metric: 'Steps', value: 8200, goal: 10000, color: '#e91e63' }, |
| 10 | +]; |
| 11 | + |
| 12 | +const dataset = healthData.map((d) => ({ |
| 13 | + metric: d.metric, |
| 14 | + progress: Math.round((d.value / d.goal) * 100), |
| 15 | +})); |
| 16 | + |
| 17 | +const highlightScope = { highlight: 'none', fade: 'none' } as const; |
| 18 | + |
| 19 | +export default function HealthRadialBarChart() { |
| 20 | + return ( |
| 21 | + <RadialBarChart |
| 22 | + height={400} |
| 23 | + dataset={dataset} |
| 24 | + series={[ |
| 25 | + { |
| 26 | + dataKey: 'progress', |
| 27 | + layout: 'horizontal', |
| 28 | + label: 'Progress', |
| 29 | + highlightScope, |
| 30 | + valueFormatter: (value) => `${value}%`, |
| 31 | + }, |
| 32 | + ]} |
| 33 | + radiusAxis={[ |
| 34 | + { |
| 35 | + scaleType: 'band', |
| 36 | + dataKey: 'metric', |
| 37 | + categoryGapRatio: 0.3, |
| 38 | + disableLine: true, |
| 39 | + disableTicks: true, |
| 40 | + colorMap: { |
| 41 | + type: 'ordinal', |
| 42 | + values: healthData.map((d) => d.metric), |
| 43 | + colors: healthData.map((d) => d.color), |
| 44 | + }, |
| 45 | + }, |
| 46 | + ]} |
| 47 | + rotationAxis={[ |
| 48 | + { |
| 49 | + scaleType: 'linear', |
| 50 | + disableTickLabel: true, |
| 51 | + disableLine: true, |
| 52 | + disableTicks: true, |
| 53 | + min: 0, |
| 54 | + max: 100, |
| 55 | + valueFormatter: (value) => `${value}%`, |
| 56 | + }, |
| 57 | + ]} |
| 58 | + axisHighlight={{ rotation: 'none', radius: 'none' }} |
| 59 | + hideLegend |
| 60 | + slotProps={{ tooltip: { trigger: 'none' } }} |
| 61 | + /> |
| 62 | + ); |
| 63 | +} |
0 commit comments