Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Example of how to call the public method Ng2Highcharts.chart() #44

Closed
lorneb opened this issue Sep 28, 2016 · 5 comments
Closed

Comments

@lorneb
Copy link

lorneb commented Sep 28, 2016

Hi does anyone have an example they can share that shows how to call the public property .chart that is found on the Ng2Highcharts class.

I'll keep looking, currently I'm heading down the road of using @ViewChild

got this working will post answer tomorrow when i'm back at work

@Bigous
Copy link
Owner

Bigous commented Sep 29, 2016

Ok this is an Angular2 question.
You can use the ViewChild or ViewChildren with better explanations on mgechev's blog

I really need some help on support this lib :D sorry, the docs and examples are far from good :(.

@Bigous Bigous closed this as completed Sep 29, 2016
@lorneb
Copy link
Author

lorneb commented Sep 29, 2016

Hey no problem, you are doing a great job. I'll add my answers back here, and perhaps put some time your way and create a PR for the docs.

@Bigous
Copy link
Owner

Bigous commented Sep 29, 2016

Just as a hint, when you use ViewChild, the chart component is created on ngAfterViewInit, but the chart itself (the highcharts part) isn't, because highcharts has some internal timeouts. If you need it, your best shot is to set a timeout on ngAfterViewInit to get the chart from the Ng2Highcharts component.

But if you need it latter, your are good to go.

@lorneb
Copy link
Author

lorneb commented Sep 30, 2016

Adding this here in the hope it can help others:

//In my example I have a lot of charts on the page and want to access them as an array
import {Component,ViewChild,ViewChildren} from '@angular/core';
import {Ng2Highcharts} from 'ng2-highcharts';

export class Foo{
   //the varialbe allCharts will be an array **eventually** that why ngAfterViewInit seems to be working
   @ViewChildren(Ng2Highcharts) allCharts


  ngAfterViewInit(){
  //I think at this stage it's safe to access the array variable.   

  var charts = [];
  charts = this.allCharts.forEach( chartRef => {
      //Access the chart property defined in Ng2Highcharts
       var theChart = chartRef.chart;

    })
  }

}

@crh225
Copy link

crh225 commented Dec 1, 2016

@lorneb , what does the html look like for your answer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants