Excel.ChartSeries class

グラフのデータ系列を表します。

Extends

注釈

API セット: ExcelApi 1.1

使用元

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-leader-lines.yaml

// The following code adds data labels to the chart and positions them to demonstrate leader lines.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  
  // Enable data labels for the series. Leader lines are enabled by default.
  series.hasDataLabels = true;
  series.points.load("items");
  await context.sync();
  
  // Load the top position for each data label.
  series.points.items.forEach((point) => point.dataLabel.load("top"));
  await context.sync();

  // Move some data labels to create distance from their chart points.
  const point1 = series.points.items[1]; 
  const point2 = series.points.items[2]; 
  point1.dataLabel.top -= 50; 
  point2.dataLabel.top += 50;
  
  // Format the data labels.
  series.dataLabels.geometricShapeType = Excel.GeometricShapeType.rectangle;
  series.dataLabels.showCategoryName = true;
  series.dataLabels.format.border.weight = 1;
  
  await context.sync();
});

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

format

塗りつぶしと線の書式設定を含む、グラフ シリーズの書式設定を表します。

name

グラフ内の系列の名前を指定します。 名前の長さは 255 文字を超えてはなりません。

points

系列内のすべてのポイントのコレクションを返します。

メソッド

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ChartSeries オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ChartSeriesData と型指定) を返します。

プロパティの詳細

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

context: RequestContext;

プロパティ値

format

塗りつぶしと線の書式設定を含む、グラフ シリーズの書式設定を表します。

readonly format: Excel.ChartSeriesFormat;

プロパティ値

注釈

API セット: ExcelApi 1.1

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-formatting.yaml

await Excel.run(async (context) => {
    const worksheet = context.workbook.worksheets.getActiveWorksheet();
    const chart = worksheet.charts.getItem("SlopeChart");
    chart.series.load("count");
    await context.sync();

    // Color everything gray before highlighting spokes.
    for (let i = 0; i < chart.series.count; i++) {
        chart.series.getItemAt(i).format.line.color = "#636363";
        chart.series.getItemAt(i).dataLabels.format.font.color = "#636363";
    }

    const highlight: Excel.ChartSeries = chart.series.getItemAt(5);
    highlight.format.line.color = "#4472C4";
    highlight.dataLabels.format.font.color = "#D9D9D9";

    highlight.load("name");
    await context.sync();
    highlight.name += " (Focus)";
    await context.sync();
});

name

グラフ内の系列の名前を指定します。 名前の長さは 255 文字を超えてはなりません。

name: string;

プロパティ値

string

注釈

API セット: ExcelApi 1.1

points

系列内のすべてのポイントのコレクションを返します。

readonly points: Excel.ChartPointsCollection;

プロパティ値

注釈

API セット: ExcelApi 1.1

例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-leader-lines.yaml

// The following code adds data labels to the chart and positions them to demonstrate leader lines.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  const series = chart.series.getItemAt(0);
  
  // Enable data labels for the series. Leader lines are enabled by default.
  series.hasDataLabels = true;
  series.points.load("items");
  await context.sync();
  
  // Load the top position for each data label.
  series.points.items.forEach((point) => point.dataLabel.load("top"));
  await context.sync();

  // Move some data labels to create distance from their chart points.
  const point1 = series.points.items[1]; 
  const point2 = series.points.items[2]; 
  point1.dataLabel.top -= 50; 
  point2.dataLabel.top += 50;
  
  // Format the data labels.
  series.dataLabels.geometricShapeType = Excel.GeometricShapeType.rectangle;
  series.dataLabels.showCategoryName = true;
  series.dataLabels.format.border.weight = 1;
  
  await context.sync();
});

メソッドの詳細

load(options)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(options?: Excel.Interfaces.ChartSeriesLoadOptions): Excel.ChartSeries;

パラメーター

options
Excel.Interfaces.ChartSeriesLoadOptions

読み込むオブジェクトのプロパティのオプションを指定します。

返品

load(propertyNames)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNames?: string | string[]): Excel.ChartSeries;

パラメーター

propertyNames

string | string[]

読み込むプロパティを指定するコンマ区切りの文字列または文字列の配列。

返品

例

// Rename the 1st series of Chart1 to "New Series Name".
await Excel.run(async (context) => { 
    const chart = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    chart.series.getItemAt(0).name = "New Series Name";
    await context.sync();

    console.log("Series1 Renamed");
});

load(propertyNamesAndPaths)

オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync() を呼び出す必要があります。

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.ChartSeries;

パラメーター

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select は読み込むプロパティを指定するコンマ区切りの文字列であり、 propertyNamesAndPaths.expand は読み込むナビゲーションのプロパティを指定するコンマ区切りの文字列です。

返品

set(properties, options)

オブジェクトの複数のプロパティを同時に設定します。 適切なプロパティを持つプレーン オブジェクト、または同じ型の別の API オブジェクトを渡すことができます。

set(properties: Interfaces.ChartSeriesUpdateData, options?: OfficeExtension.UpdateOptions): void;

パラメーター

properties
Excel.Interfaces.ChartSeriesUpdateData

メソッドが呼び出されたオブジェクトのプロパティと同型構造のプロパティを持つ JavaScript オブジェクト。

options
OfficeExtension.UpdateOptions

プロパティ オブジェクトが読み取り専用プロパティを設定しようとした場合にエラーを抑制するオプションを提供します。

返品

void

set(properties)

既存の読み込まれたオブジェクトに基づいて、オブジェクトに複数のプロパティを同時に設定します。

set(properties: Excel.ChartSeries): void;

パラメーター

properties
Excel.ChartSeries

返品

void

toJSON()

API オブジェクトが JSON.stringify() に渡されるときに、より有用な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (次に、JSON.stringify渡されたオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ChartSeries オブジェクトが API オブジェクトであるのに対し、 toJSON メソッドは、元のオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ChartSeriesData と型指定) を返します。

toJSON(): Excel.Interfaces.ChartSeriesData;

返品