@@ -29,15 +29,7 @@ $(() => {
2929 } ] ,
3030 tooltip : {
3131 enabled : true ,
32- customizeTooltip ( data ) {
33- if ( data . seriesName === 'Budget' ) {
34- return { text : formatNumber ( data . value , 'currency' ) } ;
35- }
36- const isValueAboveAverage = data . value > averageSpend ;
37- const aboveText = `${ formatNumber ( data . value , 'currency' ) } \n${ formatNumber ( data . value - averageSpend , 'currency' ) } above average spending.` ;
38- const belowText = `${ formatNumber ( data . value , 'currency' ) } \n${ formatNumber ( averageSpend - data . value , 'currency' ) } below average spending.` ;
39- return { text : isValueAboveAverage ? aboveText : belowText } ;
40- } ,
32+ customizeTooltip,
4133 } ,
4234 commonPaneSettings : {
4335 backgroundColor : {
@@ -75,11 +67,19 @@ const chartData = [
7567const averageSpend = calculateAverageSpend ( ) ;
7668
7769function calculateAverageSpend ( ) {
78- let sum = 0 ;
79-
80- chartData . forEach ( ( data ) => {
81- sum += data . actualSpend ;
82- } ) ;
70+ let sum = chartData . reduce ( ( accumulator , { actualSpend } ) => accumulator + actualSpend , 0 ) ;
8371
8472 return sum / chartData . length ;
8573}
74+
75+ function customizeTooltip ( data ) {
76+ if ( data . seriesName === 'Budget' ) {
77+ return { text : formatNumber ( data . value , 'currency' ) } ;
78+ }
79+ const isValueAboveAverage = data . value > averageSpend ;
80+ if ( isValueAboveAverage ) {
81+ return { text : `${ formatNumber ( data . value , 'currency' ) } \n${ formatNumber ( data . value - averageSpend , 'currency' ) } above average spending.` }
82+ }
83+
84+ return { text : `${ formatNumber ( data . value , 'currency' ) } \n${ formatNumber ( averageSpend - data . value , 'currency' ) } below average spending.` } ;
85+ }
0 commit comments