score:0

Accepted answer

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.


Related Query

More Query from same tag