次の方法で共有


Excel.ChartPointsCollection class

グラフ内の系列内のすべてのグラフのポイントのコレクションです。

Extends

注釈

[ API セット: ExcelApi 1.1 ]

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

// This function adds data labels to specific chart points 
// and sets their text and position.
await Excel.run(async (context) => {
  const sheet = context.workbook.worksheets.getItem(sheetName);
  const chart = sheet.charts.getItemAt(0);
  await context.sync();

  const series = chart.series.getItemAt(0);
  series.points.load("dataLabel");
  await context.sync();
  
  // Define properties for data label positioning and shape.
  const labelProperties = [
    {
      top: 70,
      geometricShapeType: Excel.GeometricShapeType.rectangle
    },
    {
      top: 200,
      geometricShapeType: Excel.GeometricShapeType.rectangle
    }
  ];

  // Add data labels to specific chart points and set their text and properties.
  for (let i = 0; i < dataLabelInfo.length; i++) {
    const point = series.points.getItemAt(dataLabelInfo[i].index);
    point.hasDataLabel = true;

    const dataLabel = point.dataLabel;
    dataLabel.text = dataLabelInfo[i].news;
    dataLabel.set(labelProperties[i]);
  }
  await context.sync();
});

プロパティ

context

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

count

系列に含まれるグラフのポイントの数を返します。

items

このコレクション内に読み込まれた子アイテムを取得します。

メソッド

getItemAt(index)

データ系列内の位置に基づくポイントを取得します。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

toJSON()

API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ChartPointsCollection オブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ChartPointsCollectionDataとして型指定) を返します。

プロパティの詳細

context

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

context: RequestContext;

プロパティ値

count

系列に含まれるグラフのポイントの数を返します。

readonly count: number;

プロパティ値

number

注釈

[ API セット: ExcelApi 1.1 ]

items

このコレクション内に読み込まれた子アイテムを取得します。

readonly items: Excel.ChartPoint[];

プロパティ値

メソッドの詳細

getItemAt(index)

データ系列内の位置に基づくポイントを取得します。

getItemAt(index: number): Excel.ChartPoint;

パラメーター

index

number

取得するオブジェクトのインデックス値。 0 を起点とする番号になります。

戻り値

注釈

[ API セット: ExcelApi 1.1 ]

// Set the border color for the first points in the points collection.
await Excel.run(async (context) => { 
    const points = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1").series.getItemAt(0).points;
    points.getItemAt(0).format.fill.setSolidColor("8FBC8F");
    await context.sync();
    
    console.log("Point Border Color Changed");
});

load(options)

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

load(options?: Excel.Interfaces.ChartPointsCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.ChartPointsCollection;

パラメーター

options

Excel.Interfaces.ChartPointsCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

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

戻り値

load(propertyNames)

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

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

パラメーター

propertyNames

string | string[]

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

戻り値

// Get the number of points.
await Excel.run(async (context) => { 
    const pointsCollection = 
        context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1").series.getItemAt(0).points;
    pointsCollection.load('count');
    await context.sync();
    console.log("points: Count= " + pointsCollection.count);
});

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.ChartPointsCollection;

パラメーター

propertyNamesAndPaths
OfficeExtension.LoadOption

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

戻り値

toJSON()

API オブジェクトがJSON.stringify()に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドをオーバーライドします。 (JSON.stringify、それに渡されるオブジェクトの toJSON メソッドを呼び出します)。元の Excel.ChartPointsCollection オブジェクトは API オブジェクトですが、 toJSON メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト ( Excel.Interfaces.ChartPointsCollectionDataとして型指定) を返します。

toJSON(): Excel.Interfaces.ChartPointsCollectionData;

戻り値