Class EmbeddedChart

Embedded Chart

Represents a chart that has been embedded into a spreadsheet.

This example shows how to modify an existing chart:

 const 
  
 sheet 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSheet 
 (); 
 const 
  
 range 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'A2:B8' 
 ); 
 let 
  
 chart 
  
 = 
  
 sheet 
 . 
 getCharts 
 ()[ 
 0 
 ]; 
 chart 
  
 = 
  
 chart 
 . 
 modify 
 () 
  
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 setOption 
 ( 
 'title' 
 , 
  
 'Updated!' 
 ) 
  
 . 
 setOption 
 ( 
 'animation.duration' 
 , 
  
 500 
 ) 
  
 . 
 setPosition 
 ( 
 2 
 , 
  
 2 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 sheet 
 . 
 updateChart 
 ( 
 chart 
 ); 

This example shows how to create a new chart:

 function 
  
 newChart 
 ( 
 range 
 ) 
  
 { 
  
 const 
  
 sheet 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSheet 
 (); 
  
 const 
  
 chartBuilder 
  
 = 
  
 sheet 
 . 
 newChart 
 (); 
  
 chartBuilder 
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 LINE 
 ) 
  
 . 
 setOption 
 ( 
 'title' 
 , 
  
 'My Line Chart!' 
 ); 
  
 sheet 
 . 
 insertChart 
 ( 
 chartBuilder 
 . 
 build 
 ()); 
 } 

Methods

Method Return type Brief description
Data Source Chart Casts to a data source chart instance if the chart is a data source chart, or null otherwise.
Blob Return the data inside this object as a blob converted to the specified content type.
Blob Return the data inside this object as a blob.
Integer Returns a stable identifier for the chart that is unique across the spreadsheet containing the chart or null if the chart is not in a spreadsheet.
Container Info Returns information about where the chart is positioned within a sheet.
Chart Hidden Dimension Strategy Returns the strategy to use for handling hidden rows and columns.
Chart Merge Strategy Returns the merge strategy used when more than one range exists.
Integer Returns the number of rows or columns the range that are treated as headers.
Chart Options Returns the options for this chart, such as height, colors, and axes.
Range[] Returns the ranges that this chart uses as a data source.
Boolean If true , the rows and columns used to populate the chart are switched.
Embedded Chart Builder Returns an Embedded Chart Builder that can be used to modify this chart.

Detailed documentation

as Data Source Chart()

Casts to a data source chart instance if the chart is a data source chart, or null otherwise.

Return

Data Source Chart — The data source chart.


get As(contentType)

Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename—for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes "ShoppingList.12.25.pdf".

To view the daily quotas for conversions, see Quotas for Google Services . Newly created Google Workspace domains might be temporarily subject to stricter quotas.

Parameters

Name Type Description
content Type
String The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp' , 'image/gif' , 'image/jpeg' , or 'image/png' are also valid. For a Google Docs document, 'text/markdown' is also valid.

Return

Blob — The data as a blob.


get Blob()

Return the data inside this object as a blob.

Return

Blob — The data as a blob.


get Chart Id()

Returns a stable identifier for the chart that is unique across the spreadsheet containing the chart or null if the chart is not in a spreadsheet.

Return

Integer — A stable chart identifier.


get Container Info()

Returns information about where the chart is positioned within a sheet.

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 addRange 
 ( 
 sheet 
 . 
 getRange 
 ( 
 'A1:B8' 
 )) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 const 
  
 containerInfo 
  
 = 
  
 chart 
 . 
 getContainerInfo 
 (); 
 // Logs the values we used in setPosition() 
 Logger 
 . 
 log 
 ( 
  
 'Anchor Column: %s\r\nAnchor Row %s\r\nOffset X %s\r\nOffset Y %s' 
 , 
  
 containerInfo 
 . 
 getAnchorColumn 
 (), 
  
 containerInfo 
 . 
 getAnchorRow 
 (), 
  
 containerInfo 
 . 
 getOffsetX 
 (), 
  
 containerInfo 
 . 
 getOffsetY 
 (), 
 ); 

Return

Container Info — an object containing the chart container's position


get Hidden Dimension Strategy()

Returns the strategy to use for handling hidden rows and columns. Defaults to IGNORE_ROWS .

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 range 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'A1:B5' 
 ); 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 setHiddenDimensionStrategy 
 ( 
  
 Charts 
 . 
 ChartHiddenDimensionStrategy 
 . 
 IGNORE_COLUMNS 
 , 
  
 ) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 // Logs the strategy to use for hidden rows and columns which is 
 // Charts.ChartHiddenDimensionStrategy.IGNORE_COLUMNS in this case. 
 Logger 
 . 
 log 
 ( 
 chart 
 . 
 getHiddenDimensionStrategy 
 ()); 

Return

Chart Hidden Dimension Strategy — The strategy to use for hidden rows and columns.


get Merge Strategy()

Returns the merge strategy used when more than one range exists. If MERGE_ROWS , row are merged; if MERGE_COLUMNS , columns are merged. Defaults to MERGE_COLUMNS .

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 range 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'A1:B10' 
 ); 
 const 
  
 range2 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'C1:C10' 
 ); 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 addRange 
 ( 
 range2 
 ) 
  
 . 
 setMergeStrategy 
 ( 
 Charts 
 . 
 ChartMergeStrategy 
 . 
 MERGE_ROWS 
 ) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 // Logs whether rows of multiple ranges are merged, which is MERGE_ROWS in this 
 // case. 
 Logger 
 . 
 log 
 ( 
 chart 
 . 
 getMergeStrategy 
 ()); 

Return

Chart Merge Strategy MERGE_ROWS if rows are merged across multiple ranges; MERGE_COLUMNS if columns are merged across multiple ranges


get Num Headers()

Returns the number of rows or columns the range that are treated as headers.

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 range 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'A1:B5' 
 ); 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 setNumHeaders 
 ( 
 1 
 ) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 // Logs the number of rows or columns to use as headers, which is 1 in this 
 // case. 
 Logger 
 . 
 log 
 ( 
 chart 
 . 
 getHeaders 
 ()); 

Return

Integer — The number of rows or columns treated as headers. Negative values indicate the headers are auto-detected.


get Options()

Returns the options for this chart, such as height, colors, and axes.

The returned options are immutable.

Return

Chart Options — The options for this chart, such as height, colors, and axes.


get Ranges()

Returns the ranges that this chart uses as a data source.

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 addRange 
 ( 
 sheet 
 . 
 getRange 
 ( 
 'A1:B8' 
 )) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 const 
  
 ranges 
  
 = 
  
 chart 
 . 
 getRanges 
 (); 
 // There's only one range as a data source for this chart, 
 // so this logs "A1:B8" 
 for 
  
 ( 
 const 
  
 i 
  
 in 
  
 ranges 
 ) 
  
 { 
  
 const 
  
 range 
  
 = 
  
 ranges 
 [ 
 i 
 ]; 
  
 Logger 
 . 
 log 
 ( 
 range 
 . 
 getA1Notation 
 ()); 
 } 

Return

Range[] — an array of ranges that serve as this chart's data source


get Transpose Rows And Columns()

If true , the rows and columns used to populate the chart are switched. Defaults to false .

 const 
  
 ss 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSpreadsheet 
 (); 
 const 
  
 sheet 
  
 = 
  
 ss 
 . 
 getSheets 
 ()[ 
 0 
 ]; 
 const 
  
 range 
  
 = 
  
 sheet 
 . 
 getRange 
 ( 
 'A1:B5' 
 ); 
 const 
  
 chart 
  
 = 
  
 sheet 
 . 
 newChart 
 () 
  
 . 
 addRange 
 ( 
 range 
 ) 
  
 . 
 setChartType 
 ( 
 Charts 
 . 
 ChartType 
 . 
 BAR 
 ) 
  
 . 
 setTransposeRowsAndColumns 
 ( 
 true 
 ) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 // Logs whether rows and columns should be transposed, which is true in this 
 // case. 
 Logger 
 . 
 log 
 ( 
 chart 
 . 
 getTransposeRowsAndColumns 
 ()); 

Return

Boolean true if the rows and columns used to construct the chart are transposed.


modify()

Returns an Embedded Chart Builder that can be used to modify this chart. Invoke sheet.updateChart(chart) to save any changes.

 const 
  
 sheet 
  
 = 
  
 SpreadsheetApp 
 . 
 getActiveSheet 
 (); 
 let 
  
 chart 
  
 = 
  
 sheet 
 . 
 getCharts 
 ()[ 
 0 
 ]; 
 chart 
  
 = 
  
 chart 
 . 
 modify 
 () 
  
 . 
 setOption 
 ( 
 'width' 
 , 
  
 800 
 ) 
  
 . 
 setOption 
 ( 
 'height' 
 , 
  
 640 
 ) 
  
 . 
 setPosition 
 ( 
 5 
 , 
  
 5 
 , 
  
 0 
 , 
  
 0 
 ) 
  
 . 
 build 
 (); 
 sheet 
 . 
 updateChart 
 ( 
 chart 
 ); 

Return

Embedded Chart Builder — a builder for creating embedded charts

Create a Mobile Website
View Site in Mobile | Classic
Share by: