Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:37:43+00:00 2026-06-17T15:37:43+00:00

I am using Google Docs and Google Apps Script to make some auto generated

  • 0

I am using Google Docs and Google Apps Script to make some auto generated report for our sprint.

I would like to add a Chart to my Sheet, and everything works fine with the following code:

    var lChartBuilder = SpreadsheetApp.getActiveSheet().newChart();
    lChartBuilder.addRange(SpreadsheetApp.getActive().getRange("Tasks!C39:S40"));
    lChartBuilder.setOption("title", "Task Burndown");

    var lChart = lChartBuilder.asLineChart().build();
    SpreadsheetApp.getActiveSheet().insertChart(lChart);

But my series are organized horizontally, not vertically. In the editor I have seen the option “Switch rows / columns” and the other option “Use column C for labels”
I have tried many options (like lChartBuilder.setOption("reverseCategories", true); or lChartBuilder.setOption("isStacked", true);), but they seem all related to the last tab, I fear, not the Start tab.

So, is there a way (other than transposing my data) to do that or must I fire the chart editor manually to fix this each time I generate it?

Bonus question: how do I then set (through Google Apps Script as well) that the first row/column is a header and serves as legend?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:37:45+00:00Added an answer on June 17, 2026 at 3:37 pm

    For an embedded chart, you will need to transpose your data, because the embedded chart uses spreadsheet data, and does not support transposition itself. However, you can handle this programmatically, and the transpose operation itself is simple.

    In the code below, I’m assuming existence of a sheet named “Scratch” that will be used to store the working copy of the transposed data. You can create and then hide this sheet, so that it’s not in the way.

    // Uses 2D Arrays Library, see https://sites.google.com/site/scriptsexamples/custom-methods/2d-arrays-library
    
    function buildChart() {
      var taskSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tasks");
      var lChartBuilder = taskSheet.newChart(); taskSheet.removeChart(chart)
      var srcData = taskSheet.getRange("Tasks!C39:S40").getValues();
    
      // Transpose the table (using 2D Array Library)
      var scratchData = ArrayLib.transpose(srcData);
    
      var numRows = scratchData.length;
      var numCols = scratchData[0].length; // assume all rows are same width
    
      // Write scratch values to scratch sheet.
      var scratchSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Scratch");
      scratchSheet.getRange(1, 1, numRows, numCols).setValues( scratchData );
      SpreadsheetApp.flush();
    
      lChartBuilder.addRange(scratchSheet.getDataRange());
      lChartBuilder.setOption("title", "Task Burndown");
    
      var lChart = lChartBuilder.asLineChart().setPosition(1, 1, 1, 1).build();
      taskSheet.insertChart(lChart);
    };
    

    For the bonus… Having the data formatted this way ensures the first row/column is a header and serves as legend.

    Resulting Chart

    Now, you’ve still got some problems to solve.

    • This code creates a new chart every time it runs, but you probably want to modify it instead. (Instead, you’ll want to update the transposed data, and modify the chart to pick up the new range, if it changed.)
    • The X axis doesn’t show all the task names – you may be able to control that.

    You say you did not want to transpose your data. Unfortunately, there just isn’t any way around that with the current incarnation of Charts – you’ve got to massage your data yourself. Inserting a widget with a different charting library could work, but widget support for Sheets has been deprecated. Fortunately, I had similar code already, so it was less work than it looks like. You should look at some of the other filtering capabilities in ArrayLib, you can do a lot with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an event signup form using Google Docs. The user
We are using Google Apps services in our startup for email and docs. However
I created this GUI https://docs.google.com/open?id=0B27WaIUHQGy0UUFwS2dMS2pMUGs using google apps script GUI builder. But when running
Using Google Apps Script, I've made a UI for use on a Google Spreadsheet.
Using Google Apps Script. I know it is not a programming issue, but got
I'm using google docs, and some templates we are using were created using MS-Office.
As described here: https://developers.google.com/apps-script/html_service#GoogleScriptAPI I am using a little form in my google app
I'm currently trying to add the facebook apps request from our java server using
I love using Google Docs function =importxml() but would love to know if there
I am using Google Apps Script with Google Drive, and I am a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.