New Columns not showing up in 'Add Series' on existing chart in Google Sheets

0

I have a chart which was created from a data range (lets say A:C) on Google Sheets.

If I add a new column (so we now have A:D), I am not able to see the new column represented in data points I can add on under Chart Editor -> Setup -> Series.

Does the chart need to be refreshed or something in order to see new Columns? I tried looking here but it didn't seem to help: How to Force New Google Spreadsheets to refresh and recalculate?

google-sheets
2021-11-24 05:26:13
1

0

To achieve this, you can use Google Apps Script. Using a trigger that fires when the document is edited onEdit() and reflecting the new content within the chart using the class EmbeddedChart.

Example

Assuming the table looks something like this (the example should work with another format):

Name Measure 1 Measure 2
Marshall 1 2
Barney 2 3
Ted 3 4

It will generate a chart like this:

Chart 1

  • First you need to open add a new script via Tools>Script Editor
  • Inside the Code.gs file, add the following:
Code.gs
const onEdit = (event) => {
  // Get the active SpreadSheet
  let ss = SpreadsheetApp.getActiveSheet()
  // If you want to limitate the range within
  // you should use the range within the Event Objects
  Logger.log(event.range)
  let chart = ss.getCharts()[0]
  // Get to A1 to the last available cell
  let newRanges = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn())
  chart = chart.modify()
     // Clear the old ones
    .clearRanges()
    // Add the updated values
    .addRange(newRanges)
    .build()
  ss.updateChart(chart)
}

The above script triggers every time you edit the sheet where it is included. Get the updated data from the spreadsheet, and include it in the chart. Right now the script detects any change in the spreadsheet and adds from the first cell to the last to the chart. Note: onEdit is too broad, you can control it using different methods, for example:

if(e.range.getRow()>20) return

For example, adding this new data:

Name Measure 1 Measure 2 Measure 3
Marshall 1 2 3
Barney 2 2 4
Ted 3 4 5
Lily 5 6 5

It will automatically generate this chart:

Chart 2

If you think this should be included in Sheets, you can also send feedback to Google using Help>Help Sheets Improve or via link.

Documentation
2021-11-24 10:51:01

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................