@@ -181,8 +181,8 @@ export class DashboardAreaChartComponent implements OnChanges {
181181 }
182182
183183 private updateChartData ( changes : SimpleChanges ) : void {
184- for ( let index = 0 ; index < this . labelsArray . length ; index ++ ) {
185- const colorIndex = index % this . chartColors . length ;
184+ this . labelsArray . forEach ( ( _label : string , index : number ) => {
185+ const colorIndex = index % this . chartColors ? .length ;
186186 this . chartData . dataset [ index ] = {
187187 label : '' ,
188188 data : [ ] ,
@@ -196,14 +196,14 @@ export class DashboardAreaChartComponent implements OnChanges {
196196 }
197197 } ;
198198 this . chartData . dataset [ index ] . label = this . labelsArray [ index ] ;
199- }
199+ } ) ;
200200
201201 this . setChartTicks ( ) ;
202202
203- if ( this . dataArray && this . dataArray . length && this . dataArray [ 0 ] && this . dataArray [ 0 ] . length ) {
203+ if ( this . dataArray ?. [ 0 ] ? .length ) {
204204 this . dataArray = changes ?. dataArray ?. currentValue || this . dataArray ;
205205 this . currentChartData = this . chartData ;
206- for ( let index = 0 ; index < this . dataArray . length ; index ++ ) {
206+ this . dataArray ?. forEach ( ( _data : Array < [ number , string ] > , index : number ) => {
207207 this . chartData . dataset [ index ] . data = this . formatData ( this . dataArray [ index ] ) ;
208208 let currentDataValue = this . dataArray ?. [ index ] ?. [ this . dataArray [ index ] ?. length - 1 ]
209209 ? this . dataArray [ index ] [ this . dataArray [ index ] ?. length - 1 ] [ 1 ]
@@ -218,7 +218,7 @@ export class DashboardAreaChartComponent implements OnChanges {
218218 ) . split ( ' ' ) ;
219219 this . currentChartData . dataset [ index ] [ 'currentDataValue' ] = currentDataValue ;
220220 }
221- }
221+ } ) ;
222222 this . currentChartData . dataset . sort (
223223 ( a : { currentDataValue : string } , b : { currentDataValue : string } ) =>
224224 parseFloat ( b [ 'currentDataValue' ] ) - parseFloat ( a [ 'currentDataValue' ] )
@@ -298,11 +298,11 @@ export class DashboardAreaChartComponent implements OnChanges {
298298 let maxValue = 0 ;
299299 let maxValueDataUnits = '' ;
300300
301- const allDataValues = this . dataArray . reduce ( ( array : string [ ] , data ) => {
301+ const allDataValues = this . dataArray ? .reduce ( ( array : string [ ] , data ) => {
302302 return array . concat ( data ?. map ( ( values : [ number , string ] ) => values [ 1 ] ) ) ;
303303 } , [ ] ) ;
304304
305- maxValue = Math . max ( ...allDataValues . map ( Number ) ) ;
305+ maxValue = allDataValues ? Math . max ( ...allDataValues . map ( Number ) ) : 0 ;
306306 [ maxValue , maxValueDataUnits ] = this . convertUnits ( maxValue ) . split ( ' ' ) ;
307307
308308 const yAxesTicks = this . chart . chart . options . scales . y ;
0 commit comments