0👍
You’re subscribing to two Observable
obtained from dataSvc.getUsers
and dataSvc.getParts
, corresponding results will be delivered asynchronously, certainly after the invocation of the constructor
has finished. Therefore, If with given code, you would invoke CreateChart()
at the end of the constructor
only, you would see two empty charts because UsersLabels
, UsersAmount
, PartsLabels
and PartsAmount
are still empty arrays at this point.
It’s however needless to recreate both charts each time any Observable
delivers new data. You better split CreateChart()
into separate methods, one for each chart. Also instead of using chart.destroy()
, you should better simply update the existing chart data
and invoke chart.update()
afterwards. Please take a look at the section Adding or Removing Data of the Chart.js documentation.