Class EmbeddedChartBuilder

EmbeddedChartBuilder

EmbeddedChart の編集に使用されるビルダー。チャートに加えた変更は、再構築されたチャートで Sheet.updateChart(chart) が呼び出されるまで保存されません。

const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1: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);

メソッド

メソッド戻り値の型概要
addRange(range)EmbeddedChartBuilderこのビルダーが変更するグラフに範囲を追加します。
asAreaChart()EmbeddedAreaChartBuilderグラフの種類を AreaChart に設定し、EmbeddedAreaChartBuilder を返します。
asBarChart()EmbeddedBarChartBuilderグラフの種類を BarChart に設定し、EmbeddedBarChartBuilder を返します。
asColumnChart()EmbeddedColumnChartBuilderグラフの種類を ColumnChart に設定し、EmbeddedColumnChartBuilder を返します。
asComboChart()EmbeddedComboChartBuilderグラフの種類を ComboChart に設定し、EmbeddedComboChartBuilder を返します。
asHistogramChart()EmbeddedHistogramChartBuilderグラフのタイプを HistogramChart に設定し、EmbeddedHistogramChartBuilder を返します。
asLineChart()EmbeddedLineChartBuilderグラフの種類を LineChart に設定し、EmbeddedLineChartBuilder を返します。
asPieChart()EmbeddedPieChartBuilderグラフの種類を PieChart に設定し、EmbeddedPieChartBuilder を返します。
asScatterChart()EmbeddedScatterChartBuilderグラフのタイプを ScatterChart に設定し、EmbeddedScatterChartBuilder を返します。
asTableChart()EmbeddedTableChartBuilderグラフのタイプを TableChart に設定し、EmbeddedTableChartBuilder を返します。
build()EmbeddedChartグラフをビルドして、グラフに加えられたすべての変更を反映します。
clearRanges()EmbeddedChartBuilderこのビルダーが変更するグラフからすべての範囲を削除します。
getChartType()ChartType現在のグラフの種類を返します。
getContainer()ContainerInfoグラフがシートのどこに表示されるかをカプセル化するグラフ ContainerInfo を返します。
getRanges()Range[]現在このグラフにデータを提供している範囲のリストのコピーを返します。
removeRange(range)EmbeddedChartBuilderこのビルダーが変更するグラフから、指定された範囲を削除します。
setChartType(type)EmbeddedChartBuilderグラフの種類を変更します。
setHiddenDimensionStrategy(strategy)EmbeddedChartBuilder非表示の行と列に使用する戦略を設定します。
setMergeStrategy(mergeStrategy)EmbeddedChartBuilder複数の範囲が存在する場合に使用するマージ戦略を設定します。
setNumHeaders(headers)EmbeddedChartBuilder範囲の行または列のうち、ヘッダーとして扱う行または列の数を設定します。
setOption(option, value)EmbeddedChartBuilderこのグラフの詳細オプションを設定します。
setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)EmbeddedChartBuilder位置を設定し、シート上のグラフの表示位置を変更します。
setTransposeRowsAndColumns(transpose)EmbeddedChartBuilderグラフの行と列を入れ替えるかどうかを設定します。

詳細なドキュメント

addRange(range)

このビルダーが変更するグラフに範囲を追加します。範囲がすでにグラフに追加されている場合は、範囲を追加しません。

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();  sheet.insertChart(chart);

パラメータ

名前説明
rangeRange追加する範囲。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


asAreaChart()

グラフの種類を AreaChart に設定し、EmbeddedAreaChartBuilder を返します。

戻る

EmbeddedAreaChartBuilder - 面グラフのビルダー。


asBarChart()

グラフの種類を BarChart に設定し、EmbeddedBarChartBuilder を返します。

戻る

EmbeddedBarChartBuilder - 棒グラフのビルダー。


asColumnChart()

グラフの種類を ColumnChart に設定し、EmbeddedColumnChartBuilder を返します。

戻る

EmbeddedColumnChartBuilder - 縦棒グラフのビルダー。


asComboChart()

グラフの種類を ComboChart に設定し、EmbeddedComboChartBuilder を返します。

戻る

EmbeddedComboChartBuilder - 複合グラフのビルダー。


asHistogramChart()

グラフのタイプを HistogramChart に設定し、EmbeddedHistogramChartBuilder を返します。

戻る

EmbeddedHistogramChartBuilder - ヒストグラム グラフのビルダー。


asLineChart()

グラフの種類を LineChart に設定し、EmbeddedLineChartBuilder を返します。

戻る

EmbeddedLineChartBuilder - 折れ線グラフのビルダー。


asPieChart()

グラフの種類を PieChart に設定し、EmbeddedPieChartBuilder を返します。

戻る

EmbeddedPieChartBuilder - 円グラフのビルダー。


asScatterChart()

グラフのタイプを ScatterChart に設定し、EmbeddedScatterChartBuilder を返します。

戻る

EmbeddedScatterChartBuilder - 散布図のビルダー。


asTableChart()

グラフのタイプを TableChart に設定し、EmbeddedTableChartBuilder を返します。

戻る

EmbeddedTableChartBuilder - テーブルグラフのビルダー。


build()

グラフをビルドして、グラフに加えられたすべての変更を反映します。

このメソッドでは、スプレッドシートの上にグラフが自動的に描画されることはありません。新しいグラフは sheet.insertChart(chart) を介して挿入し、既存のグラフは sheet.updateChart(chart) を介して更新する必要があります。

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)                   .setPosition(5, 5, 0, 0)                   .build();  sheet.insertChart(chart);

戻る

EmbeddedChart - 作成されたグラフ。スプレッドシートに追加する必要があります。


clearRanges()

このビルダーが変更するグラフからすべての範囲を削除します。

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This code updates the chart to use only the new ranges while preserving the // existing formatting of the chart. const chart = sheet.getCharts()[0]; const newChart = chart.modify()                      .clearRanges()                      .addRange(sheet.getRange('A1:A5'))                      .addRange(sheet.getRange('B1:B5'))                      .build(); sheet.updateChart(newChart);

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


getChartType()

現在のグラフの種類を返します。

戻る

ChartType - グラフの種類。


getContainer()

シート上のグラフの表示位置をカプセル化するグラフ ContainerInfo を返します。

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const chartBuilder = sheet.newChart()                          .setChartType(Charts.ChartType.BAR)                          .addRange(sheet.getRange('A1:B8'))                          .setPosition(5, 5, 0, 0);  // This method returns the exact same data as Chart#getContainerInfo() const containerInfo = chartBuilder.getContainer();  // 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(), );

戻る

ContainerInfo - グラフ コンテナの位置を含むオブジェクト。


getRanges()

現在このグラフにデータを提供している範囲のリストのコピーを返します。このリストを変更するには、addRange(range)removeRange(range) を使用します。

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const chartBuilder = sheet.newChart()                          .setChartType(Charts.ChartType.BAR)                          .addRange(sheet.getRange('A1:B8'))                          .setPosition(5, 5, 0, 0);  const ranges = chartBuilder.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()); }

戻る

Range[] - 作成するグラフのデータソースとして機能する範囲の配列。


removeRange(range)

このビルダーが変更するグラフから、指定された範囲を削除します。範囲がこのグラフにない場合、エラーはスローされません。

削除された範囲は、addRange(range) で追加された範囲と一致している必要があります。一致していない場合、グラフは変更されません。このメソッドを使用して、範囲から値を部分的に削除することはできません。

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const firstRange = sheet.getRange('A1:B5'); const secondRange = sheet.getRange('A6:B8');  const chartBuilder = sheet.newChart()                          .setChartType(Charts.ChartType.BAR)                          .addRange(firstRange)                          // This range renders in a different color                          .addRange(secondRange)                          .setPosition(5, 5, 0, 0);  // Note that you can use either of these two formats, but the range // MUST match up with a range that was added via addRange(), or it // is not removed, and does not throw an exception chartBuilder.removeRange(firstRange); chartBuilder.removeRange(sheet.getRange('A6:B8'));  const chart = chartBuilder.build();  sheet.insertChart(chart);

パラメータ

名前説明
rangeRange削除する範囲。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setChartType(type)

グラフの種類を変更します。現在、すべての埋め込みグラフタイプがサポートされているわけではありません。ChartType をご覧ください。

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)                   .setPosition(5, 5, 0, 0)                   .build();  sheet.insertChart(chart);

パラメータ

名前説明
typeChartTypeこのグラフの変更先の種類。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setHiddenDimensionStrategy(strategy)

非表示の行と列に使用する戦略を設定します。デフォルトは 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();  sheet.insertChart(chart);

パラメータ

名前説明
strategyChartHiddenDimensionStrategy非表示の行と列に使用する戦略。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setMergeStrategy(mergeStrategy)

複数の範囲が存在する場合に使用するマージ戦略を設定します。MERGE_ROWS の場合、行が結合されます。MERGE_COLUMNS の場合、列が結合されます。デフォルトは MERGE_COLUMNS です。

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const range = sheet.getRange('A1:B10'); const range2 = sheet.getRange('C:C10'); const chart = sheet.newChart()                   .setChartType(Charts.ChartType.BAR)                   .addRange(range)                   .addRange(range2)                   .setMergeStrategy(Charts.ChartMergeStrategy.MERGE_ROWS)                   .setPosition(5, 5, 0, 0)                   .build();  sheet.insertChart(chart);

パラメータ

名前説明
mergeStrategyChartMergeStrategy使用する統合戦略。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setNumHeaders(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();  sheet.insertChart(chart);

パラメータ

名前説明
headersIntegerヘッダーとして扱う行または列の数。負の値を指定すると、ヘッダーが自動検出されます。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setOption(option, value)

このグラフの詳細オプションを設定します。使用可能なオプションの一覧を表示するには、グラフの構成オプションをご覧ください。

このメソッドは、指定したオプションがこのグラフタイプで有効かどうか、値が正しい形式/構造かどうかを検証しません。

この例では、タイトルを変更して凡例を設定する方法を示します。

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); const sheet = spreadsheet.getSheets()[0]; const chart = sheet.newChart()  .setOption('title', 'Earnings projections')  .setOption('legend', {    position: 'top',    textStyle: { color: 'blue', fontSize: 16 },  }).build();

パラメータ

名前説明
optionStringオプションの名前。
valueObjectオプションの値。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)

位置を設定し、シート上のグラフの表示位置を変更します。anchorRowPosanchorColPos は 1 から始まるインデックスです。

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)                   .setPosition(5, 5, 0, 0)                   .build();  sheet.insertChart(chart);

パラメータ

名前説明
anchorRowPosIntegerグラフの上部はこの行に固定されます。
anchorColPosIntegerグラフの左側はこの列に固定されます。
offsetXIntegerグラフの右上隅がこのピクセル数だけオフセットされます。
offsetYIntegerグラフの左下隅がこのピクセル数だけオフセットされます。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。


setTransposeRowsAndColumns(transpose)

グラフの行と列を入れ替えるかどうかを設定します。true に設定すると、行と列が入れ替わります。デフォルトは false です。

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)                   .setTransposeRowsAndColumns(true)                   .setPosition(5, 5, 0, 0)                   .build();  sheet.insertChart(chart);

パラメータ

名前説明
transposeBooleantrue の場合、グラフの作成に使用される行と列が転置されます。

戻る

EmbeddedChartBuilder - チェーン用のこのビルダー。