As of version 4.67, the Google Sheets connector works in a standalone fashion

Written by Richard Heyes, on 28th July 2018

The Google Sheets connector no longer requires the RGraph core file to be included into your page. So you can now use it with your own code if you want to and not have to include an unnecessary JavaScript file.

As promised, I've updated both the canvas and SVG versions of the Google Sheets connector so that they no longer require the RGraph core file to be included in the page.

This means that you can make use of the Google Sheets connector with your own JavaScript code if you want and you don't have to include the RGraph core file into your page.

Since this file is quite large, especially when it's uncompressed, this means that you can save a fair amount of unnecesary page weight.

Example code

Here's an example page. You can copy this to a file on your desktop or on your website and run it from there.

It uses the example spreadsheet that I setup specifically for the examples and you can see that here:

Remember that the ID of the spreadsheet that you give to the Sheets connector is this:

You can view this file online here.

<!DOCTYPE html >
<html>
<head>
    <script src="https://www.rgraph.net/libraries/RGraph.common.sheets.js" ></script>
    
    <title>Using the Google Sheets import code standalone</title>

    <meta name="robots" content="noindex, nofollow" />
    
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 125%;
        }
    </style>
</head>
<body>

    <h1>Using the Google Sheets import code standalone</h1>
    
    <p>
        This is a demo page that demonstrates how the Google Sheets import code can
        now be used standalone - ie without any other RGraph files. View the source
        to see the code or go to the blog page and get the source there:
    </p>
    
    <ul>
        <li><a href="https://www.rgraph.net/blog/standalone-google-sheets-connector.html">Blog post about the standalone Google Sheets connector</a></li>
        <li><a href="https://docs.google.com/spreadsheets/d/1ncvARBgXaDjzuca9i7Jyep6JTv9kms-bbIzyAxbaT0E/edit?usp=sharing">The Google Docs spreadsheet</a></li>
    </ul>
    
    <script>
        RGraph.Sheets('1ncvARBgXaDjzuca9i7Jyep6JTv9kms-bbIzyAxbaT0E', function (sheet)
        {
            // Get some examples
            var row1  = sheet.get('1'),
                row2  = sheet.get('A1:C1'),
                col1  = sheet.get('A'),
                col2  = sheet.get('A1:A7'),
                cell1 = sheet.get('A2');
            
            alert('Results of fetching row1: ' + row1);
            alert('Results of fetching row2: ' + row2);
            alert('Results of fetching col1: ' + col1);
            alert('Results of fetching col2: ' + col2);
            alert('Results of fetching cell A2: ' + cell1);
        });
    </script>

</body>
</html>