Create multiple dynamic charts

前端 未结 2 1956
忘了有多久
忘了有多久 2021-02-06 13:18

i\'m developing a web application - MEAN stack. i\'m trying to use ChartJS doughnut chart but i need it to be completely dynamic - first, the number of charts is dynamic (each c

2条回答
  •  悲哀的现实
    2021-02-06 13:53

    In your

    canvas ... add a #yourId

    (example : canvas *ngFor="let chart of charts; let i = index" id="canvas{{i}} #yourId")

    Then you can use @ViewChildren('yourId') myCharts: any; (you can't use myCharts in ngOnInit, only in ngAfterViewInit and after) which will give you your array of charts.

    I won't provide much more detail but you can use what's inside your myCharts (use a console.log(myCharts) to see in detail what's in there), you can use this to change data and so on.

    Hope this helps.

提交回复
热议问题