# An SVG Bar chart using the Google Sheets connector

This is a Bar chart that's getting information from a Google Sheets spreadsheet using the connector that's supplied with RGraph. The connector can get information from any worksheet should you have multiple - but this is fetching data from the first. The labels are arranged such that every other label is prefixed by a unicode white-space character and a linebreak - giving a two line appearance for the labels.

You can see the Google Sheet that RGraph is fetching data from here.

This goes in the documents header:

    <script src="RGraph.svg.common.core.js"></script>
    <script src="RGraph.svg.common.sheets.js"></script>
    <script src="RGraph.svg.bar.js"></script>

Put this where you want the chart to show up:

    <div style="width: 700px; height: 300px" id="chart-container"></div>

This is the code that generates the chart:

    <script>
        new RGraph.Sheets('1ncvARBgXaDjzuca9i7Jyep6JTv9kms-bbIzyAxbaT0E', function (sheet)
        {
            var data   = sheet.get('B2:B13'),
                labels = sheet.get('A2:A13');

            // TODO Carriage retyurns don't work yet
            for (var i=0; i<labels.length; i+=2) {
                labels[i] = "\u00A0\n" + labels[i];
            }

            new RGraph.SVG.Bar({
                id: 'chart-container',
                data: data,
                options: {
                    backgroundGridVlines: false,
                    backgroundGridBorder: false,
                    yaxis: false,
                    colors: ['Gradient(rgb(102, 102, 204):rgb(102, 102, 204):white)'],
                    xaxisLabels: labels
                }
            }).draw();
        });
    </script>