Trying to resolve API Key issue

124 views
Skip to first unread message

moresugarmore

unread,
Nov 14, 2016, 4:55:04 PM11/14/16
to Google Visualization API
Hello,

I am getting the google api key error for my google chart maps.

I am fetching data from which I am displaying a variety of charts. This meant that I needed to be able to load the google api and set a callback and pass the callback the data I just got from the ajax. 


google.load('visualization', '1.0', {'packages':['corechart','bar','table','controls','map'] , "callback" : function()
    {
        buildCharts(data);
    }
});


I wasn't able to pass data using the way described in the documentation.

google.charts.setOnLoadCallback(drawChart);

... which is why instead I included the jsapi and then loaded the visualization module that way. This seemed to be the only way I can both specify a callback and also give that callback data.

But now I have the API key error and I read that I need to use v45 or "upcoming". This doesn't appear to be a valid setting for version when loading the google visualization module in this way. And it also doesn't seem to be using the <mapsApiKey> param.


Is there a way for me to do a callback and also pass data using "setOnLoadCallback" so that I can load the google charts using:

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

??? Or can someone help me figure out the correct way for me to call the module, tell it what version to use and give it an api key?

Thank you!

Daniel LaLiberte

unread,
Nov 15, 2016, 10:41:19 AM11/15/16
to Google Visualization API
Hi

It's not clear whether you are using the correct loader with your google.charts calls.  You must be loading the www.gstatic.com/charts.loader.js rather than the jsapi loader. This documentation spells out the details: https://developers.google.com/chart/interactive/docs/basic_load_libs#update-library-loader-code  And the mapsApiKey setting only works, so far, with v45 loaded with the gstatic loader. 

If you are loading the library correctly, then we can look into what happened.  Can you point us at a page that demonstrates what you are seeing?  It is difficult to guess what might be happening otherwise. Thanks.

--
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 google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/c496f7e6-d605-4604-b317-ba5ff3bbd56a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

moresugarmore

unread,
Nov 15, 2016, 12:16:26 PM11/15/16
to Google Visualization API
Hello Daniel,

I mentioned in my post that while I understand the documentation instructs us to use www.gstatic.com/charts.loader.js , this didn't work out for me because I could not find a way for this method to be able to pass data into the callback I was setting.

I found another way to call the charts, which works fine for all other charts. That is to use the api loader and specify the module I want, as documented here:


Using this method, I am able to send my ajax data to my callback function. I showed that from above too.

I could not find any way to use  setOnLoadCallback() to set a callback and also pass my data. If there is a way please let me know.

Thank you!

Daniel LaLiberte

unread,
Nov 15, 2016, 1:07:12 PM11/15/16
to Google Visualization API
The callback function is called with no args, but you can wrap anything with a function(){ ... } to have it pass data to your chart drawing function.  That's what you did when you provided a 'callback' function setting.  Do the same thing in your setOnLoadCallback() call.  e.g. 

google.charts.setOnLoadCallback(function()
    {
        buildCharts(data);
    });

--
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 google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.

moresugarmore

unread,
Nov 16, 2016, 11:46:01 AM11/16/16
to Google Visualization API
Daniel,

Totally right, I don't know why I didn't put the wrapping function in! Been sitting here bashing away at it for nothing. That's perfect, so now I have the whole thing in there and it works fine. 

Thanks thanks!

google.charts.load('upcoming', { mapsApiKey: myKey, 'packages': ['controls','map'] });
    google.charts.setOnLoadCallback(function()
        {
            buildCharts(data);
        });


Reply all
Reply to author
Forward
0 new messages