Hi Andrea,

That kind of error, "google is not defined", means that at the time you use
the google symbol, the loader has not finished loading.  I suspect the
problem might be that ngOnInit is called before the component html has been
defined and/or used, so the loader has not necessarily finished loading.

Since your app-component html really looks more like a full page, including
html head and body, maybe you should separate out the chart drawing parts
into a chart-component.

On Wed, Sep 30, 2020 at 9:36 AM Andrea Buzzi <[email protected]> wrote:

>
> Hello,
> due to some missing feature on  "FERNman / angular-google-charts" wrapper
> (like: role "style"/"annotation") I'm trying to feed the classic "google.
> charts.load" into a fresh test-ui angular project (v10).
>
> So far I've put in app.component.html:
>
> <html>
>   <head>
>    <script type="text/javascript" src="
> https://www.gstatic.com/charts/loader.js";></script>
>   </head>
>
>   <body>
>    <div id="donutchart" style="width: 900px; height: 500px; border:solid
> 1px black"></div>
>   </body>
> </html>
>
> while app.component.ts I've the following:
>
> import { Component } from '@angular/core';
>
> declare var google: any;
>
> @Component({
>   selector: 'app-root',
>   templateUrl: './app.component.html',
>   styleUrls: ['./app.component.css']
> })
>
> export class AppComponent {
>   title = 'test-ui';
>
>   drawChart=function() {
>   var data = google.visualization.arrayToDataTable([['Task', 'Hours per
> Day'], ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep',
> 7] ]);
>   var options = { title: 'My Daily Activities', pieHole: 0.4 };
>   var chart = new   google.visualization.PieChart(document.getElementById(
> 'donutchart'));
>   chart.draw(data, options);
> }
>
> ngOnInit() {
>   google.charts.load('current', {'packages':['corechart']});
>   google.charts.setOnLoadCallback(this.drawChart);
> }
>
> }
>
>
> Unfortunately this generate a "ERROR ReferenceError: google is not
> defined"...
>
> Any tip to make this sample graph working in a angular environment ?
>
> Thx in advance for any suggestion/hint/example!
>
> Andrea
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-visualization-api/435f4d45-d323-476c-8821-fc7c8c57dda5n%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/435f4d45-d323-476c-8821-fc7c8c57dda5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
[email protected] <[email protected]>   Cambridge MA

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJP_wB1mkd4JyzKrrGHDvQbwqwoufV9H6FVqbkqArRFx1g%40mail.gmail.com.

Reply via email to