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

Accessing google.visualization #14

Closed
jkon opened this issue Aug 28, 2018 · 9 comments
Closed

Accessing google.visualization #14

jkon opened this issue Aug 28, 2018 · 9 comments
Labels
feature New feature or request

Comments

@jkon
Copy link

jkon commented Aug 28, 2018

I was wondering how you suggest to add the google object to an angular project so it can be access for making formatters or some of the more advanced chart operations (currently trying to figure out how to do a bar diff chart)
Thanks

@FERNman
Copy link
Owner

FERNman commented Aug 29, 2018

I've just published a new version of the package that exports the ScriptLoaderService. You'd have to inject this service into your custom component and then wait for onLoad to be called. Just see the Google-Charts-Component as an example.

@jkon
Copy link
Author

jkon commented Aug 29, 2018

Sweet, thanks!

@jkon
Copy link
Author

jkon commented Aug 29, 2018

so, I see how you used the script loader service to get the chart packages, but what if I want to make a formatter? I still need the google.visualization object, right? Like in your formatter example:

 myFormatter = [
  { formatter: new google.visualization.Dateformat({formatType: 'long'}), colIndex: 1 },
  { formatter: new google.visualization.Dateformat({formatType: 'long'}), colIndex: 3 }
]; 

@jkon
Copy link
Author

jkon commented Aug 29, 2018

Having a new issue after updating to 0.0.7. All of my module.ngfactory.js files are throwing this error:
"export 'ɵa' (imported as 'i39') was not found in 'angular-google-charts'

@jkon
Copy link
Author

jkon commented Aug 29, 2018

i downgraded to 0.0.6 and had the same errors. had to go back to 0.0.5 to get rid of them

@FERNman
Copy link
Owner

FERNman commented Aug 29, 2018

Could you please provide explanation on how to reproduce this?

@jkon
Copy link
Author

jkon commented Aug 29, 2018

I tried to create a stackblitz to reproduce, but I can't seem to. It must be something specific to my project. I can add that when I try to render the chart, I get this error after every change detection:
TypeError: ctor is not a constructor
at _createClass (core.js:10628)
at createProviderInstance$1 (core.js:10602)
at resolveNgModuleDep (core.js:10553)
at NgModuleRef
.get (core.js:11595)
at resolveDep (core.js:12074)
at createClass (core.js:11934)
at createDirectiveInstance (core.js:11777)
at createViewNodes (core.js:13239)
at createEmbeddedView (core.js:13116)
at callWithDebugContext (core.js:14524)

I'm not sure what's going on or why it is happening with the newer versions only

@jkon
Copy link
Author

jkon commented Aug 29, 2018

hm, I have been trying to create a stackblitz example that reproduces the errors I was seeing, but I just couldn't. I added all the modules my app imports and couldn't. So, I decided to try seeing if it was a package version issue with some other package, so I blew out my local node_modules and reinstalled everything and now the errors are gone from my project. Just one of those shruggie moments. Anyway, while building the stackblitz I also did an example of how to use the script loader service. Here is a snippet of how I used it to make a formatter that I think could help others:

constructor( private loaderService: ScriptLoaderService ) {}

  ngOnInit() {
    this.loaderService.onReady.subscribe( () => {
      this.loaderService.loadChartPackages(this.type).subscribe( () => {
        console.log('loaded chart packages');
        const formatter = new google.visualization.BarFormat();
        console.log(formatter);
      });
      
    });
  }

It's worth noting that this.type needs to be the translated string that your package returns with [GoogleChartPackagesHelper.getPackageForChartName(this.type)]. That helper isn't available, so I had to look at it to figure out what string to actually pass. That helper being available would be nice.
Again, thanks for the quick turnaround on exposing the service

FERNman added a commit that referenced this issue Aug 30, 2018
Inspired by #14 and also used the code example provided there
@FERNman FERNman added the feature New feature or request label Aug 30, 2018
@FERNman
Copy link
Owner

FERNman commented Aug 30, 2018

Thanks for the code example, I've added a new section to the readme based on it! 👍

I'm also happy that everything worked out for you, I'll close this one now.

@FERNman FERNman closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants