valor-software / ng2-charts

Beautiful charts for Angular based on Chart.js
http://valor-software.github.io/ng2-charts/
MIT License
2.35k stars 575 forks source link

How to use ViewChild with multiple charts #1136

Open rabac opened 5 years ago

rabac commented 5 years ago

Hi This is a question. In the example for line chart on your homepage, you use @ViewChild to get a reference to the chart object. What if you have multiple charts in the same component. How can I get a reference to a specific chart using ViewChild. And secondly, whats the benefit of using ng2-charts compared with the charts wrapper from bootstrap-md module (which has a mdbChart directive). thanks rajesh.

Lkledu commented 5 years ago

how are your component? it's with mutiple tag? or it's being dinamycally created?

Lkledu commented 5 years ago

i'm trying to create a chart carousel with multiple slides being dinamycally creted. I'm using *ngFor to create the <slide #slides> tag inside the caroulsel and getting then in my component with ViewChildren('slides') slides: QueryList<ViewContainerRef>

the *ngFor is to create slides with the number of components returned by a http get.

The only problem i'm having is to use createComponent( ) method with my queryList elements through forEach. The angular changes the type of my queryList<ViewContainerRef> to SlideComponent.

I think we can help each other

Lkledu commented 5 years ago

I solved my problem with the component returned by ViewChildren using {read: ViewContainerRef}. Now it's returning a ViewContainerRef for each one of QueryList children.