Stay organized with collections Save and categorize content based on your preferences.
EmbeddedChartRepresents 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()); }Detailed documentation
asDataSourceChart()
Casts to a data source chart instance if the chart is a data source chart, or null
otherwise.
DataSourceChart
— The data source chart.
getAs(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 DescriptioncontentType
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.
getBlob()
Return the data inside this object as a blob.
ReturnBlob
— The data as a blob.
getChartId()
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.
Integer
— A stable chart identifier.
getContainerInfo()
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 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
ContainerInfo
— An object containing the chart container's position.
getMergeStrategy()
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
ChartMergeStrategy
— MERGE_ROWS
If rows are merged across multiple ranges; MERGE_COLUMNS
if columns are merged across multiple ranges.
getOptions()
Returns the options for this chart, such as height, colors, and axes.
The returned options are immutable.
ReturnChartOptions
— The options for this chart, such as height, colors, and axes.
getRanges()
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.
getTransposeRowsAndColumns()
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 EmbeddedChartBuilder
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
EmbeddedChartBuilder
— A builder for creating embedded charts.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-04 UTC."],[[["`EmbeddedChart` represents a chart embedded within a Google Sheet and allows for modifications or creation of new charts programmatically."],["Charts can be modified by adding data ranges, updating titles, setting animation durations, and changing positions using the `modify()` method."],["New charts can be created by defining the chart type, data range, title and inserting it into the sheet using the `newChart()` function."],["`EmbeddedChart` provides methods like `getOptions()`, `getRanges()`, and `getChartId()` to access chart properties, data sources, and identifiers."],["Chart customization options include handling hidden data with `setHiddenDimensionStrategy()`, merging data with `setMergeStrategy()`, and transposing data with `setTransposeRowsAndColumns()`."]]],["The `EmbeddedChart` class manages charts within spreadsheets. Key actions include modifying existing charts by adjusting their data range, title, animation, and position, demonstrated via the `.modify()` method. New charts can be created using a builder (`sheet.newChart()`), specifying the chart type and data range. Various methods exist to retrieve chart properties such as ID, data ranges, options, and container information, alongside settings for hidden data handling, header number, and row/column merging or transposition.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4