Question

I would like to know if it is possible to download and include the jsapi library, but not hosted by google.com, hosted on my local machine. Because it's possible that my project can not have access to the Web.

Was it helpful?

Solution

You can't.

You can download jsapi.js and save it in your local machine, but it will still refer to the on-line version on google.com. You can see it by opening the jsapi.js code.

See this Google developers article for more.

Can I use charts offline?

No; your computer must have live access to http://www.google.com/jsapi in order to use charts. This is because the visualization libraries that your page requires are loaded dynamically before you use them. The code for loading the appropriate library is part of the included jsapi script, and is called when you invoke the google.load() method. Our terms of service do not allow you to download the google.load or google.visualization code to use offline.

Can I download and host the chart code locally, or on an intranet?

Sorry; our terms of service do not allow you to download and save or host the google.load or google.visualization code.

OTHER TIPS

Although you can do that and dowlnoad jsapi all other code is still on google servers, visualisation libs, and so on an it is not in terms of service, which forbids it.

Can I use charts offline? No; your computer must have live access to http://www.google.com/jsapi in order to use charts. This is because the visualization libraries that your page requires are loaded dynamically before you use them. The code for loading the appropriate library is part of the included jsapi script, and is called when you invoke the google.load() method. Our terms of service do not allow you to download the google.load or google.visualization code to use offline. Can I download and host the chart code locally, or on an intranet? Sorry; our terms of service do not allow you to download and save or host the google.load or google.visualization code.

jsapi.js file alone won't do any good because it requests a truck load of other scripts and css files when you load stuff using it.

So if you really want to make your app offline with Google Charts, first include the jsapi.js in your app and monitor the other files it requests over the wire (using something like Fiddler). Then download them as well and include in your app. Remember it could be a deep rabbit hole IYKWIM.

Also keep in mind that all of the above voilates Google's Terms and Conditions for using their charts.

Absolutely, although only as a proof of concept. Just open and save the following file as jsapi.js to your local machine :

http://www.google.com/jsapi

Then, add a reference to it from your HTML page:

    <script type="text/javascript" src="jsapi.js"></script>

See an example at:

http://www.marlenynunez.com/files/jsapi/horizontal-news-ticker4.html From answer to question [question]: jquery horizontal news ticker using google jsapi

But, as others have pointed out, you might still need web access and the terms of service for the API don't allow its use on this way.

Hi have used below concept to add the file locally in anguarjs application and its working fine for development purpose..

/* global angular */
(function(){
    angular.module('googlechart')
        .provider('googleJsapiUrl', googleJsapiUrlProvider);

    function googleJsapiUrlProvider() {
        var protocol = 'http:';
        var url = '//localhost/yourApplicationName/Scripts/chart/jsapi.js';

        this.setProtocol = function (newProtocol) {
            protocol = newProtocol;
        };

        this.setUrl = function (newUrl) {
            url = newUrl;
        };

        this.$get = function () {
            return (protocol ? protocol : '') + url;
        };
    }
})();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top