@@ -8,19 +8,19 @@ import { LineChart, areaElementClasses } from '@mui/x-charts/LineChart';
8
8
const data = [ 4000 , 3000 , - 1000 , 500 , - 2100 , - 250 , 3490 ] ;
9
9
const xData = [ 'Page A' , 'Page B' , 'Page C' , 'Page D' , 'Page E' , 'Page F' , 'Page G' ] ;
10
10
11
- type ColorSwichProps = {
11
+ type ColorSwitchProps = {
12
12
threshold : number ;
13
13
color1 : string ;
14
14
color2 : string ;
15
15
id : string ;
16
16
} ;
17
17
18
- function ColorSwich ( { threshold, color1, color2, id } : ColorSwichProps ) {
18
+ function ColorSwitch ( { threshold, color1, color2, id } : ColorSwitchProps ) {
19
19
const { top, height, bottom } = useDrawingArea ( ) ;
20
20
const svgHeight = top + bottom + height ;
21
21
22
22
const scale = useYScale ( ) as ScaleLinear < number , number > ; // You can provide the axis Id if you have multiple ones
23
- const y0 = scale ( threshold ) ; // The coordinate of of the origine
23
+ const y0 = scale ( threshold ) ; // The coordinate of the origin
24
24
const off = y0 !== undefined ? y0 / svgHeight : 0 ;
25
25
26
26
return (
@@ -45,42 +45,42 @@ export default function AreaChartFillByValue() {
45
45
< Stack direction = "column" width = "100%" spacing = { 1 } >
46
46
< LineChart
47
47
xAxis = { [ { data : xData , scaleType : 'point' } ] }
48
- yAxis = { [ { min : - 3000 , max : 4000 } ] }
48
+ yAxis = { [ { min : - 3000 , max : 4000 , width : 40 } ] }
49
49
series = { [ { data, showMark : false , area : true } ] }
50
50
height = { 200 }
51
- margin = { { top : 20 , bottom : 30 , left : 75 } }
51
+ margin = { { bottom : 0 } }
52
52
sx = { {
53
53
[ `& .${ areaElementClasses . root } ` ] : {
54
- fill : 'url(#swich -color-id-1)' ,
54
+ fill : 'url(#switch -color-id-1)' ,
55
55
filter : 'none' , // Remove the default filter.
56
56
} ,
57
57
} }
58
58
>
59
- < ColorSwich
59
+ < ColorSwitch
60
60
color1 = "#11B678" // green
61
61
color2 = "#FF3143" // red
62
62
threshold = { 0 }
63
- id = "swich -color-id-1"
63
+ id = "switch -color-id-1"
64
64
/>
65
- < rect x = { 0 } y = { 0 } width = { 5 } height = "100%" fill = "url(#swich -color-id-1)" />
65
+ < rect x = { 0 } y = { 0 } width = { 5 } height = "100%" fill = "url(#switch -color-id-1)" />
66
66
</ LineChart >
67
67
68
68
< LineChart
69
69
xAxis = { [ { data : xData , scaleType : 'point' } ] }
70
- yAxis = { [ { min : - 3000 , max : 4000 } ] }
70
+ yAxis = { [ { min : - 3000 , max : 4000 , width : 40 } ] }
71
71
series = { [ { data, showMark : false , area : true } ] }
72
72
height = { 200 }
73
- margin = { { top : 20 , bottom : 30 , left : 75 } }
73
+ margin = { { bottom : 0 } }
74
74
sx = { {
75
75
[ `& .${ areaElementClasses . root } ` ] : {
76
- fill : 'url(#swich -color-id-2)' ,
76
+ fill : 'url(#switch -color-id-2)' ,
77
77
filter : 'none' , // Remove the default filter.
78
78
} ,
79
79
} }
80
80
>
81
- < ColorPalette id = "swich -color-id-2" />
81
+ < ColorPalette id = "switch -color-id-2" />
82
82
83
- < rect x = { 0 } y = { 0 } width = { 5 } height = "100%" fill = "url(#swich -color-id-2)" />
83
+ < rect x = { 0 } y = { 0 } width = { 5 } height = "100%" fill = "url(#switch -color-id-2)" />
84
84
</ LineChart >
85
85
</ Stack >
86
86
) ;
0 commit comments