Skip to content

Instantly share code, notes, and snippets.

@acurtis517
Forked from njoerd114/README.MD
Created October 13, 2025 14:40
Show Gist options
  • Save acurtis517/54c2556e47737bdec9df1c2913336516 to your computer and use it in GitHub Desktop.
Save acurtis517/54c2556e47737bdec9df1c2913336516 to your computer and use it in GitHub Desktop.

Revisions

  1. @njoerd114 njoerd114 revised this gist Jun 9, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.MD
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    - create the two files `code.gs` and `index.html`
    - insert the document ID from the URL on line 10, `code.gs`
    - select which sheet is the base for the sankey diagram
    - the layout of the table should be
    - the layout of the table should be as shown in the [Example Spreadsheet](https://docs.google.com/spreadsheets/d/1IUmvhYuuBvfYEu8OfDczmW6LQW-xaeh5c6rklOg3x-o/)

    ## Usage
    - Open the same document
  2. @njoerd114 njoerd114 revised this gist Jun 9, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.MD
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,4 @@
    - Click "Zusatzfunktionen" -> "SankeyDiagram"

    ## Example Spreadsheet
    https://docs.google.com/spreadsheets/d/1IUmvhYuuBvfYEu8OfDczmW6LQW-xaeh5c6rklOg3x-o/edit?usp=sharing
    https://docs.google.com/spreadsheets/d/1IUmvhYuuBvfYEu8OfDczmW6LQW-xaeh5c6rklOg3x-o/
  3. @njoerd114 njoerd114 revised this gist Jun 9, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion README.MD
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,5 @@
    - Open the same document
    - Click "Zusatzfunktionen" -> "SankeyDiagram"

    source | destination | value
    ## Example Spreadsheet
    https://docs.google.com/spreadsheets/d/1IUmvhYuuBvfYEu8OfDczmW6LQW-xaeh5c6rklOg3x-o/edit?usp=sharing
  4. @njoerd114 njoerd114 revised this gist Jun 9, 2020. No changes.
  5. @njoerd114 njoerd114 revised this gist Jun 9, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.MD
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,9 @@
    - insert the document ID from the URL on line 10, `code.gs`
    - select which sheet is the base for the sankey diagram
    - the layout of the table should be

    ## Usage
    - Open the same document
    - Click "Zusatzfunktionen" -> "SankeyDiagram"

    source | destination | value
  6. @njoerd114 njoerd114 created this gist Jun 9, 2020.
    15 changes: 15 additions & 0 deletions README.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <!-- [![njoerd114](https://avatars1.githubusercontent.com/u/3825200?v=3&s=200)](http://niklasbeinghaus.com) -->

    # Sankey Diagrams within Google Spreadsheets

    > This Gist is there to help you creating a Sankey Diagram from your Google Spreadsheets.
    ## Installation

    - Open a spreadsheet
    - Click "Tools" -> "Scripts"
    - create the two files `code.gs` and `index.html`
    - insert the document ID from the URL on line 10, `code.gs`
    - select which sheet is the base for the sankey diagram
    - the layout of the table should be
    source | destination | value
    23 changes: 23 additions & 0 deletions code.gs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    function onOpen() {
    SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
    .createMenu('Zusatzfunktionen')
    .addItem('SankeyDiagram', 'openDialog')
    .addToUi();
    }

    function getSpreadsheetData() {
    // ID of your Document, take from URL
    var ssID = "",
    // which Sheet? [0] is the first and so on...
    sheet = SpreadsheetApp.openById(ssID).getSheets()[0],
    data = sheet.getDataRange().getValues();
    return data;
    }

    function openDialog() {
    var html = HtmlService.createHtmlOutputFromFile('index')
    .setHeight(300)
    .setWidth(1000);
    SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
    .showModalDialog(html, 'Sankey Diagram');
    }
    28 changes: 28 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@


    <!DOCTYPE html>
    <html>
    <head>
    <base target="_top">
    <script src="https://www.google.com/jsapi"></script>
    </head>
    <body>
    <div id="main"></div>
    <script type="text/javascript">
    google.load('visualization', '1', {
    packages: ['corechart', 'sankey']
    }); google.setOnLoadCallback(initialize);

    function initialize() {
    google.script.run.withSuccessHandler(drawChart).getSpreadsheetData();
    }

    function drawChart(rows) {
    console.log(rows);
    var data = google.visualization.arrayToDataTable(rows);
    var chart = new google.visualization.Sankey(document.getElementById('main'));
    chart.draw(data, {width: 900, sankey: {iterations: 64}});
    }
    </script>
    </body>
    </html>