25

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
Elmux
  • 399
  • 1
  • 4
  • 14

5 Answers5

25

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.

MorganGalpin
  • 685
  • 6
  • 7
hari mow
  • 282
  • 3
  • 2
  • 1
    There's a difference between "You can't." and "It might be challenging to...". Please consider rewording as it is indeed possible to achieve this behavior offline as stated in some of the more creative answers. – vhs Jun 11 '17 at 04:55
12

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.

Diego Barros
  • 2,071
  • 2
  • 33
  • 45
Harpo Marx
  • 139
  • 1
  • 7
  • This says basically the same thing as the currently accepted answer. Please consider deleting. – vhs Jun 11 '17 at 05:01
2

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.

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
  • Rules were made to be broken. Nice answer! One could also use a browser [`Cache`](http://devdocs.io/dom/cache) to save all of the files for offline use without requiring the use of an HTTP proxy. – vhs Jun 11 '17 at 04:56
1

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.

Community
  • 1
  • 1
marlenunez
  • 626
  • 4
  • 9
  • 1
    Finaly, I have used PChart [http://www.pchart.net/](http://www.pchart.net/) Thanks for help ! – Elmux Mar 09 '12 at 19:03
  • 8
    But the jsapi file makes further requests to Google UDS when loaded, so this does not work if you are completely offline – David Dec 21 '13 at 22:36
  • I have tried this, but i still see the browser reporting `waiting for www.google.com...` – Pathros Apr 08 '15 at 19:43
  • @David I realize it's 4 years later now, but even four years ago your comment was not correct. All that's needed is to cache the responses and reverse proxy to the cache for offline use. – vhs Jun 11 '17 at 05:03
0

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;
        };
    }
})();
SantoshK
  • 1,789
  • 16
  • 24