1
1
import * as React from 'react' ;
2
2
import { BarChartPro } from '@mui/x-charts-pro/BarChartPro' ;
3
+ import { BarChartProps } from '@mui/x-charts/BarChart' ;
3
4
4
- const defaultXAxis = {
5
- id : 'angle0' ,
5
+ const defaultYAxis = {
6
6
scaleType : 'band' ,
7
7
dataKey : 'code' ,
8
- position : 'bottom' ,
9
- zoom : true ,
10
- height : 80 ,
8
+ width : 100 ,
11
9
valueFormatter : ( value : any ) =>
12
10
usAirportPassengers . find ( ( item ) => item . code === value ) ! . fullName ,
13
11
label : '0deg Axis Title' ,
14
12
} as const ;
15
13
14
+ const degrees = [ - 180 , - 135 , - 90 , - 45 , 0 , 45 , 90 , 135 , 180 ] ;
15
+
16
+ type AxisPosition = NonNullable < BarChartProps [ 'yAxis' ] > [ number ] [ 'position' ] ;
17
+
18
+ const yAxes = degrees
19
+ . map ( ( angle ) => ( {
20
+ ...defaultYAxis ,
21
+ position : 'left' as AxisPosition ,
22
+ id : `angle${ angle } ` ,
23
+ label : `${ angle } deg Axis Title` ,
24
+ tickLabelStyle : { angle } ,
25
+ } ) )
26
+ . concat (
27
+ degrees . map ( ( angle ) => ( {
28
+ ...defaultYAxis ,
29
+ id : `right-angle${ angle } ` ,
30
+ label : `${ angle } deg Axis Title` ,
31
+ position : 'right' ,
32
+ tickLabelStyle : { angle } ,
33
+ } ) ) ,
34
+ ) satisfies BarChartProps [ 'yAxis' ] ;
35
+
16
36
export default function XAxisTickLabelOverflow ( ) {
17
37
return (
18
38
< BarChartPro
19
- xAxis = { [
20
- {
21
- ...defaultXAxis ,
22
- id : 'angle-90' ,
23
- label : '-90deg Axis Title' ,
24
- tickLabelStyle : {
25
- angle : - 90 ,
26
- textAnchor : 'end' ,
27
- dominantBaseline : 'central' ,
28
- } ,
29
- } ,
30
-
31
- {
32
- ...defaultXAxis ,
33
- id : 'angle-45' ,
34
- label : '-45deg Axis Title' ,
35
- tickLabelStyle : {
36
- angle : - 45 ,
37
- textAnchor : 'end' ,
38
- dominantBaseline : 'central' ,
39
- } ,
40
- } ,
41
- defaultXAxis ,
42
- {
43
- ...defaultXAxis ,
44
- id : 'angle45' ,
45
- label : '45deg Axis Title' ,
46
- tickLabelStyle : {
47
- angle : 45 ,
48
- textAnchor : 'start' ,
49
- } ,
50
- } ,
51
- {
52
- ...defaultXAxis ,
53
- id : 'angle90' ,
54
- label : '90deg Axis Title' ,
55
- tickLabelStyle : {
56
- angle : 90 ,
57
- textAnchor : 'start' ,
58
- dominantBaseline : 'central' ,
59
- } ,
60
- } ,
61
- ] }
39
+ yAxis = { yAxes }
62
40
// Other props
63
- height = { 600 }
41
+ width = { 1600 }
64
42
dataset = { usAirportPassengers }
65
43
series = { [
66
44
{ dataKey : '2018' , label : '2018' } ,
@@ -70,10 +48,9 @@ export default function XAxisTickLabelOverflow() {
70
48
{ dataKey : '2022' , label : '2022' } ,
71
49
] }
72
50
hideLegend
73
- yAxis = { [
51
+ xAxis = { [
74
52
{
75
53
valueFormatter : ( value ) => `${ ( value / 1000 ) . toLocaleString ( ) } k` ,
76
- width : 40 ,
77
54
} ,
78
55
] }
79
56
/>
0 commit comments