@@ -10,26 +10,39 @@ import {
1010} from 'recharts' ;
1111
1212const data = [
13- { ageGroup : '18 - 21' , applicants : 25 } ,
14- { ageGroup : '21 - 24' , applicants : 60 } ,
15- { ageGroup : '24 - 27' , applicants : 45 } ,
16- { ageGroup : '27 - 30' , applicants : 7 } ,
17- { ageGroup : '30 - 33' , applicants : 10 } ,
13+ { ageGroup : '18 - 21' , applicants : 25 , change : 10 } ,
14+ { ageGroup : '21 - 24' , applicants : 60 , change : - 5 } ,
15+ { ageGroup : '24 - 27' , applicants : 45 , change : 15 } ,
16+ { ageGroup : '27 - 30' , applicants : 7 , change : - 3 } ,
17+ { ageGroup : '30 - 33' , applicants : 10 , change : 0 } ,
1818] ;
1919
2020function ApplicantsChartPage ( ) {
21+ const formatTooltip = ( value , name , props ) => {
22+ const { change } = props . payload ;
23+ let changeText = '' ;
24+ if ( change > 0 ) {
25+ changeText = `${ change } % more than last week` ;
26+ } else if ( change < 0 ) {
27+ changeText = `${ Math . abs ( change ) } % less than last week` ;
28+ } else {
29+ changeText = `No change from last week` ;
30+ }
31+ return [ `${ value } (${ changeText } )` , 'Applicants' ] ;
32+ } ;
33+
2134 return (
22- < div style = { { width : '100% ' , height : 500 , padding : '20px' } } >
35+ < div style = { { width : '800px ' , height : 500 , margin : '0 auto' , padding : '20px' } } >
2336 < h2 > Applicants grouped by Age</ h2 >
2437 < ResponsiveContainer width = "100%" height = "100%" >
25- < BarChart data = { data } margin = { { top : 20 , right : 30 , left : 20 , bottom : 20 } } >
38+ < BarChart data = { data } margin = { { top : 20 , right : 30 , left : 20 , bottom : 20 } } barSize = { 80 } >
2639 < CartesianGrid strokeDasharray = "3 3" />
2740 < XAxis
2841 dataKey = "ageGroup"
2942 label = { { value : 'Age Group' , position : 'insideBottom' , offset : - 10 } }
3043 />
3144 < YAxis label = { { value : 'Applicants' , angle : - 90 , position : 'insideLeft' } } />
32- < Tooltip />
45+ < Tooltip formatter = { formatTooltip } />
3346 < Bar dataKey = "applicants" fill = "#3b82f6" >
3447 < LabelList dataKey = "applicants" position = "top" />
3548 </ Bar >
0 commit comments