Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run Google Charts locally?

I am looking at using Google Charts to have scatter plot. All of the examples have external dependency, and I would like to avoid that as this is an intranet application that doesn't have external Internet access.

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
 <script type="text/javascript">
   google.charts.load('current', {packages: ['corechart']});
   google.charts.setOnLoadCallback(drawChart);
...
</script>

Can I simply just copy loader.js locally or is there something more complicated that I need to worry about here? The reason I ask is that I tried doing that and it's not working so I am trying to figure out if what I am doing is fundamentally flawed or I might have an unrelated issue.

like image 882
leora Avatar asked Dec 16 '16 14:12

leora


People also ask

Can Google Charts be used offline?

NO! Your users' computers must have access to https://www.gstatic.com/charts/loader.js in order to use the interactive features of Google Charts.

Can I download Google Charts?

On your computer, open a spreadsheet in Google Sheets. Click your chart. Download as. Choose your file type.

How do I access Google Charts?

The most common way to use Google Charts is with simple JavaScript that you embed in your web page. You load some Google Chart libraries, list the data to be charted, select options to customize your chart, and finally create a chart object with an id that you choose.

Is Google Charts API free?

Google chart tools are powerful, simple to use, and free. Try out our rich gallery of interactive charts and data tools.


2 Answers

No. It is not allowed per the Google agreements https://developers.google.com/chart/interactive/faq

Off line use is not allowed.

like image 172
Kevin Brown Avatar answered Oct 09 '22 09:10

Kevin Brown


You should be able to run charts/loader.js locally and have it work just fine. I just copied and pasted its contents into a new js file and my charts rendered as normal.

The source code is too large for me to use as a snippet in the answer, but here's a working fiddle that uses the pasted code from charts/loader.js to create a table: https://jsfiddle.net/q078fvw1/

If you right click on the file in your header that reads

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

This ought to work.

If not, then it's probably something on your system that's causing the interference.

Edit: While my answer might be literally correct vis a vis being able to use the source code locally, I wasn't making any recommendations with regards to whether or not this is the best thing to do.

As another poster pointed out, if it's in their service agreement not to use it locally then it's wise to comply with their terms.

like image 35
Jonathan Bechtel Avatar answered Oct 09 '22 09:10

Jonathan Bechtel