membersound
membersound

Reputation: 86925

How to load google charts with frozen library?

Normally the google charts library is loaded as follows, which works fine:

google.load('visualization', '1', {packages: ['corechart']});

var data = new google.visualization.arrayToDataTable(v);
var chart = new google.visualization.LineChart(elm[0]);
chart.draw(data, options);

Now I want to switch to a frozen version of the corecharts. The docs state this is to be done as follows:

google.charts.load('41', {packages: ['corechart']});

@see https://developers.google.com/chart/interactive/docs/library_loading_enhancements

Problem: Using this, I'm getting the error in javascript that google.visualization is not defined.

So, how do I have to load the frozen version?

Upvotes: 0

Views: 573

Answers (2)

Dr.Molle
Dr.Molle

Reputation: 117354

The issue is not the loading, the issue is the moment when you access google.visualization.

The documentation states that you should supply a callback for google.charts.setOnLoadCallback where you create the chart, but you don't.

As it seems the scripts will be loaded synchronously (via document.write ) when you load the library normally, but when you load the frozen version the scripts will be loaded asynchronously(via appendChild), that's why your attempt fails(the scripts have not been loaded completely when you try to access google.visualization)

Upvotes: 1

perhapsOneDay
perhapsOneDay

Reputation: 1

Did you change the source of script tag ?

<script type="text/javascript" 
    src="https://www.google.com/jsapi"></script>

to

<script type="text/javascript" 
    src="https://www.gstatic.com/charts/loader.js"></script>

Upvotes: 0

Related Questions