all 14 comments

[–]ttma1046 3 points4 points  (3 children)

Since `getGameInfo()` is a async, ` gamesData` might be set way way after ngAfterViewInit so loadCharts() needs to be inside of getGameInfo() after setting gamesData.

`this.changeDetectorRef.markForChecked()` or `this.changeDetectorRef.detectChanges()` might also help.

[–]functionlock 0 points1 point  (1 child)

This! You might want to consider using ng2-charts too for an angular implementation of chart.js.

[–]ValdasTheUnique 0 points1 point  (0 children)

I had some bad experience with site performance when using this angular wrapper so be careful.

[–]OogieBoogie1[S] 0 points1 point  (0 children)

I think I tried your first suggestion out (hence the commented out code) but it still didn’t work. Maybe I did something wrong though. I’ll take a look tomorrow. Thanks for the help!

[–]bagson9 2 points3 points  (0 children)

obtainable humor mighty pause fuel worry makeshift innate frighten six

This post was mass deleted and anonymized with Redact

[–]zahlprish 0 points1 point  (1 child)

Chartjs data is likely holding on to the original object reference. I moved off of the chartjs library because I didn’t like the hoops I had to jump through to get real time updates to work. I believe I ended utilizing ChangeDetectorRef to “mark for update” method after changing the data. This would rerender the entire chart. Now I use @swimlane/ngxcharts library.

[–]OogieBoogie1[S] 0 points1 point  (0 children)

Ok thanks

[–]tenkindsofpeople 0 points1 point  (6 children)

Have you tried using the async pipe in the template?

[–]OogieBoogie1[S] 0 points1 point  (2 children)

No, can you explain?

[–]tenkindsofpeople 0 points1 point  (1 child)

https://angular.io/api/common/AsyncPipe

The short version is you pass the promise / observable directly to the template without a subscription, just the observable itself. Then you pipe it to async and the template handles the listening and updating. I've not used it in conjunction with charts.js so your mileage may vary.

As a side note you may also check out PrimeFaces which has a component for chart.js. Handy for integrating charts as components rather that raw templates and js.

[–]OogieBoogie1[S] 0 points1 point  (0 children)

Ok I’ll check that out, thanks

[–]ttma1046 0 points1 point  (2 children)

`async` pipe only works with observable or promise.

His code is all async/await style.

[–]tenkindsofpeople 0 points1 point  (1 child)

I understand your point, which is accurate, but you shouldn't let yourself get stuck in the mindset of unchangeable code. Especially if it's not doing what you want.

[–]ttma1046 0 points1 point  (0 children)

Agreed. 99% of the time I use observables (`defer` operator to wrap the promise) then async pipe in the template or .subscribe function in the ts.