C++でプレゼンテーションのチャート データ シリーズを管理する
概要
チャートはプロットされたデータをチャート データ ワークブックに保存します。 IChartSeries は関連する値のセットを表し、シリーズ内の各 IChartDataPoint は 1 つ以上のワークブック セルを参照します。 IChartCategory オブジェクトはシリーズで共有されるラベルまたはグループ化値を提供します。したがって、シリーズ名、カテゴリ、およびポイント値は、表示テキストとしてのみ保存されるのではなく、IChartDataCell オブジェクトに接続されています。
典型的なカテゴリ チャートの場合、既定のワークブックは行 0 をシリーズ名、列 0 をカテゴリ名、残りのセルをシリーズ値に使用します。IChartDataWorkbook::GetCell に渡すワークシート、行、列のインデックスは 0 ベースです。このレイアウトは既定データでチャートを作成する際に便利ですが、すべての既存チャートがこれを使用しているとは限りません。読み込んだプレゼンテーションの場合は、ワークブックの値を変更する前に、シリーズ、カテゴリ、データ ポイントが参照しているセルを確認してください。
チャート設定には 3 つの異なるスコープがあります。
- シリーズ レベルの設定(例: IChartSeries::get_Format)は、1 つのシリーズ内のすべてのポイントの既定の外観を提供します。
- データ ポイントの設定(例: IChartDataPoint::get_Format)は、1 つのポイントのシリーズ外観を上書きします。
- グループ設定は、同じ IChartSeriesGroup に属する互換性のあるシリーズに適用されます。重なりやギャップ幅などのオプションを設定する必要がある場合は、IChartSeries::get_ParentSeriesGroup を介してグループにアクセスしてください。
明示的なポイントまたはシリーズの塗りつぶしが設定されていない場合、チャート スタイルとテーマが自動外観を決定します。シリーズとポイントの書式設定が両方存在する場合、ポイントの書式設定がそのポイントに対して優先されます。

チャート シリーズの重なりを設定する
IChartSeries::get_Overlap は、2D チャートにおけるバーまたは列の重なり率(-100 から 100 パーセント)を報告します。これは親シリーズ グループの設定の読み取り専用の投影です。グループ内のすべての互換シリーズを更新するには、IChartSeriesGroup::set_Overlap を呼び出します。このオプションは、グループ化されたバーまたは列を表示するチャート タイプに適用され、組み合わせチャートの無関係なシリーズ グループには影響しません。
以下の例は、最初のシリーズを含むグループの重なりを設定します。
#include <cstdint>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeriesGroup.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/shared_ptr.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::Presentation;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
const int8_t overlapPercent = 30;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
// 新しいチャートにはサンプルのシリーズ、カテゴリ、および値が含まれています。
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
series->get_ParentSeriesGroup()->set_Overlap(overlapPercent);
presentation->Save(u"series_overlap.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果:

シリーズの塗りつぶし色を変更する
IChartSeries::get_Format を使用して、シリーズ全体の既定の塗りつぶしを設定します。ポイントに明示的な塗りつぶしが既に設定されている場合は、その IChartDataPoint::get_Format 設定がポイントのシリーズ塗りつぶしを上書きします。
以下の例は、最初のシリーズに単色の青い塗りつぶしを適用します。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IFormat.h>
#include <DOM/FillType.h>
#include <DOM/IChart.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/shared_ptr.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::FillType;
using Aspose::Slides::Presentation;
using System::Drawing::Color;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
auto seriesColor = Color::get_Blue();
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(seriesColor);
presentation->Save(u"series_color.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果:

シリーズ名を変更する
シリーズ名はチャート データ ワークブックに格納され、通常は凡例に表示されます。クラスター化された縦棒チャート用に作成された既定のワークブックでは、セル B1 が行 0、列 1 にあり、最初のシリーズ名が格納されています。以下の例の名前付き定数は、その構造を明示的に示します。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::Presentation;
using System::ObjectExt;
using System::String;
const int firstSlideIndex = 0;
const int worksheetIndex = 0;
const int seriesNameRowIndex = 0;
const int firstSeriesColumnIndex = 1;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto workbook = chart->get_ChartData()->get_ChartDataWorkbook();
auto seriesNameCell = workbook->GetCell(worksheetIndex, seriesNameRowIndex, firstSeriesColumnIndex);
auto seriesName = ObjectExt::Box<String>(u"Revenue");
seriesNameCell->set_Value(seriesName);
presentation->Save(u"series_name.pptx", SaveFormat::Pptx);
presentation->Dispose();
また、IChartSeries::get_Name が参照しているセルを直接更新することもできます。この方法は、既存チャートで特定の行・列を想定することを回避します。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartCellCollection.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IStringChartValue.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::Presentation;
using System::ObjectExt;
using System::String;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
const int firstNameCellIndex = 0;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
auto seriesNameCells = series->get_Name()->get_AsCells();
auto seriesNameCell = seriesNameCells->idx_get(firstNameCellIndex);
auto seriesName = ObjectExt::Box<String>(u"Revenue");
seriesNameCell->set_Value(seriesName);
presentation->Save(u"series_name.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果:

複数セルから名前を取得してシリーズを作成する
製品名と報告期間が別々のワークブック セルに格納されている場合、複合シリーズ名が便利です。たとえば、B1 の Product A と C1 の 2026 を組み合わせて、両方のパーツが元のセルにリンクされたまま単一のシリーズ名にできます。
IChartDataWorkbook::GetCellCollection を使用して名前範囲を取得し、そのコレクションを IChartSeriesCollection::Add に渡します。skipHiddenCells 引数は非表示セルを含めるかどうかを制御します:true は除外し、false は含めます。この例は false を使用して名前範囲のすべてのセルを含めています。
以下の例は、1 つのシリーズと 2 つのデータ ポイントを持つプレゼンテーションを作成します。セル B1:C1 がシリーズ名のみを供給し、A2:A3 がカテゴリ ラベル、B2:B3 が数値を供給します。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartCellCollection.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using System::ObjectExt;
using System::String;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 50.0f, 50.0f, 620.0f, 180.0f);
auto chartData = chart->get_ChartData();
chartData->get_Series()->Clear();
chartData->get_Categories()->Clear();
chart->set_HasLegend(true);
auto workbook = chartData->get_ChartDataWorkbook();
workbook->Clear(0);
// これら 2 つのセルがシリーズ名を提供します。
auto productName = ObjectExt::Box<String>(u"Product A");
auto reportingPeriod = ObjectExt::Box<String>(u"2026");
workbook->GetCell(0, 0, 1, productName);
workbook->GetCell(0, 0, 2, reportingPeriod);
auto nameCells = workbook->GetCellCollection(u"Sheet1!$B$1:$C$1", false);
auto series = chartData->get_Series()->Add(nameCells, ChartType::ClusteredColumn);
// 別々のセルがカテゴリと数値データ ポイントを提供します。
auto northLabel = ObjectExt::Box<String>(u"North");
auto southLabel = ObjectExt::Box<String>(u"South");
auto northCategory = workbook->GetCell(0, 1, 0, northLabel);
auto southCategory = workbook->GetCell(0, 2, 0, southLabel);
chartData->get_Categories()->Add(northCategory);
chartData->get_Categories()->Add(southCategory);
auto northAmount = ObjectExt::Box<int>(120);
auto southAmount = ObjectExt::Box<int>(150);
auto northValue = workbook->GetCell(0, 1, 1, northAmount);
auto southValue = workbook->GetCell(0, 2, 1, southAmount);
series->get_DataPoints()->AddDataPointForBarSeries(northValue);
series->get_DataPoints()->AddDataPointForBarSeries(southValue);
presentation->Save(u"composite_series_name.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果として得られるシリーズ名は Product A 2026 で、2 つのセル値の間にスペースが入ります。凡例は 2 列を 1 つのエントリとして表示します。以下の画像は結果を示しています。

自動シリーズ塗りつぶし色を取得する
IChartSeries::GetAutomaticSeriesColor は、シリーズインデックスとチャート スタイルから計算された色を返します。これは、シリーズの塗りつぶしが明示的に定義されていない場合に使用される色です。メソッドを呼び出すと計算された色が取得されますが、新しい塗りつぶしが設定されるわけではありません。
以下の例は、既定の各シリーズの自動色を出力します。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <drawing/color.h>
#include <system/console.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Presentation;
using System::Console;
using System::String;
const int firstSlideIndex = 0;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
const int seriesCount = seriesCollection->get_Count();
for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++)
{
auto series = seriesCollection->idx_get(seriesIndex);
auto automaticColor = series->GetAutomaticSeriesColor();
auto colorName = automaticColor.get_Name();
auto outputLine = String::Format(u"Series {0}: {1}", seriesIndex, colorName);
Console::WriteLine(outputLine);
}
presentation->Dispose();
既定チャート スタイルのサンプル出力:
Series 0: ff4f81bd
Series 1: ffc0504d
Series 2: ff9bbb59
正確な色はチャート スタイルとテーマに依存します。
チャート シリーズの負の値用塗りつぶし色を反転する
棒、縦棒、およびバブル シリーズの場合、IChartSeries::set_InvertIfNegative を使用して負の値を別の塗りつぶしで表示できます。通常のシリーズ塗りつぶしを単色に設定し、反転を有効にし、負の値の色を IChartSeries::get_InvertedSolidFillColor で割り当てます。ワークブック内の負の数値は変更されず、表示色だけが変わります。
以下の例は、デフォルトのチャート データを 1 系列に置き換えます。ワークシートの行 0 にシリーズ名、列 0 にカテゴリ名、列 1 に値が格納されます。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IFormat.h>
#include <DOM/FillType.h>
#include <DOM/IChart.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::FillType;
using Aspose::Slides::Presentation;
using System::Drawing::Color;
using System::ObjectExt;
using System::String;
const int firstSlideIndex = 0;
const int worksheetIndex = 0;
const int headerRowIndex = 0;
const int categoryColumnIndex = 0;
const int firstSeriesColumnIndex = 1;
const int firstDataRowIndex = 1;
const int categoryCount = 3;
const String categoryNames[] = {u"Category 1", u"Category 2", u"Category 3"};
const int seriesValues[] = {-20, 50, -30};
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto chartData = chart->get_ChartData();
auto workbook = chartData->get_ChartDataWorkbook();
auto seriesCollection = chartData->get_Series();
seriesCollection->Clear();
chartData->get_Categories()->Clear();
auto seriesName = ObjectExt::Box<String>(u"Series 1");
auto seriesNameCell = workbook->GetCell(worksheetIndex, headerRowIndex, firstSeriesColumnIndex, seriesName);
auto chartType = chart->get_Type();
auto series = seriesCollection->Add(seriesNameCell, chartType);
for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++)
{
const int dataRowIndex = firstDataRowIndex + categoryIndex;
auto categoryName = categoryNames[categoryIndex];
const int seriesValue = seriesValues[categoryIndex];
auto boxedCategoryName = ObjectExt::Box<String>(categoryName);
auto categoryCell = workbook->GetCell(worksheetIndex, dataRowIndex, categoryColumnIndex, boxedCategoryName);
chartData->get_Categories()->Add(categoryCell);
auto boxedSeriesValue = ObjectExt::Box<int>(seriesValue);
auto valueCell = workbook->GetCell(worksheetIndex, dataRowIndex, firstSeriesColumnIndex, boxedSeriesValue);
series->get_DataPoints()->AddDataPointForBarSeries(valueCell);
}
auto automaticSeriesColor = series->GetAutomaticSeriesColor();
auto invertedSeriesColor = Color::get_Red();
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(automaticSeriesColor);
series->set_InvertIfNegative(true);
series->get_InvertedSolidFillColor()->set_Color(invertedSeriesColor);
presentation->Save(u"inverted_solid_fill_color.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果:

1 ポイントだけに反転を有効にするには、IChartDataPoint::set_InvertIfNegative を使用します。以下の例では、シリーズ全体の反転を無効にし、選択されたポイントだけに有効にしています。そのポイントには負の値も割り当てられているため、効果が確認できます。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataPoint.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IDoubleChartValue.h>
#include <DOM/Chart/IFormat.h>
#include <DOM/FillType.h>
#include <DOM/IChart.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::FillType;
using Aspose::Slides::Presentation;
using System::Drawing::Color;
using System::ObjectExt;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
const int targetDataPointIndex = 2;
const int negativeValue = -30;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
auto automaticSeriesColor = series->GetAutomaticSeriesColor();
auto invertedSeriesColor = Color::get_Red();
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(automaticSeriesColor);
series->get_InvertedSolidFillColor()->set_Color(invertedSeriesColor);
series->set_InvertIfNegative(false);
auto dataPoint = series->get_DataPoint(targetDataPointIndex);
auto boxedNegativeValue = ObjectExt::Box<int>(negativeValue);
dataPoint->get_YValue()->get_AsCell()->set_Value(boxedNegativeValue);
dataPoint->set_InvertIfNegative(true);
presentation->Save(u"data_point_invert_color_if_negative.pptx", SaveFormat::Pptx);
presentation->Dispose();
特定のデータ ポイントの値をクリアする
他のポイントを削除せずに 1 ポイントだけを空にするには、そのバックアップ ワークブック セルを nullptr に設定します。縦棒チャートの場合、プロットされた値は IChartDataPoint::get_YValue で取得できます。データ ポイントは同じカテゴリ位置に残りますが、チャートは空白設定に従ってその値を空として扱います。
以下の例は、最初のシリーズの 2 番目のポイントだけをクリアします。
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataPoint.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IDoubleChartValue.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/shared_ptr.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::Presentation;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
const int targetDataPointIndex = 1;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
auto dataPoint = series->get_DataPoint(targetDataPointIndex);
dataPoint->get_YValue()->get_AsCell()->set_Value(nullptr);
presentation->Save(u"clear_data_point_value.pptx", SaveFormat::Pptx);
presentation->Dispose();
散布図は X と Y のセルが別々で、バブル チャートはサイズセルも使用します。削除したい値に対応するセルだけをクリアしてください。ポイント コレクション全体を削除したい場合以外は、IChartDataPointCollection::Clear を呼び出さないでください。
空白セルの表示を制御する
値を保持した非表示セルは、空白セルとは別のケースです。非表示の行や列からデータを含めるか除外する方法については、非表示の行と列からデータを含める を参照してください。
空白のワークブック セルはデータが欠落していることを表し、0 を含むセルは既知の数値を表します。セルを空にしたい場合は、IChartDataCell::set_Value に nullptr を渡します。数値のゼロは空白設定に関係なくゼロのままです。
IChart::set_DisplayBlanksAs を使用して、チャートが空白セルをどのように表示するかを選択します。この設定はチャート全体に適用され、空白のプロット方法を変更しますが、空白セル自体にゼロや補間値が入力されることはありません。
以下の自己完結型サンプルは、1 系列の折れ線グラフを作成し、Day 3 の値をクリアして、各モードで同じチャートを保存します。入力ファイルは不要です。IChartDataWorkbook はワークシート 0、列 0 にカテゴリ ラベル、列 1 に値を使用し、行 0 にシリーズ名を保持します。最終データは 10, 20, empty, 30, 40 です。
#include <array>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/DisplayBlanksAsType.h>
#include <DOM/Chart/IChartCategoryCollection.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartDataCell.h>
#include <DOM/Chart/IChartDataPointCollection.h>
#include <DOM/Chart/IChartDataWorkbook.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
#include <system/shared_ptr.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using System::ObjectExt;
using System::String;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto chart = slide->get_Shapes()->AddChart(ChartType::LineWithMarkers, 40.0f, 40.0f, 640.0f, 400.0f);
auto chartData = chart->get_ChartData();
auto workbook = chartData->get_ChartDataWorkbook();
chartData->get_Series()->Clear();
chartData->get_Categories()->Clear();
auto seriesName = ObjectExt::Box<String>(u"Measurements");
auto seriesNameCell = workbook->GetCell(0, 0, 1, seriesName);
auto series = chartData->get_Series()->Add(seriesNameCell, chart->get_Type());
auto values = std::array<int, 5>{10, 20, 25, 30, 40};
for (auto i = 0; i < values.size(); i++)
{
auto categoryName = String::Format(u"Day {0}", i + 1);
auto boxedCategoryName = ObjectExt::Box<String>(categoryName);
auto categoryCell = workbook->GetCell(0, i + 1, 0, boxedCategoryName);
chartData->get_Categories()->Add(categoryCell);
auto boxedValue = ObjectExt::Box<int>(values[i]);
auto valueCell = workbook->GetCell(0, i + 1, 1, boxedValue);
series->get_DataPoints()->AddDataPointForLineSeries(valueCell);
}
// Day 3 を実際に空にしたまま、カテゴリとデータ ポイントは保持します。
workbook->GetCell(0, 3, 1)->set_Value(nullptr);
auto modes = std::array<DisplayBlanksAsType, 3>{DisplayBlanksAsType::Gap, DisplayBlanksAsType::Zero, DisplayBlanksAsType::Span};
for (auto mode : modes)
{
chart->set_DisplayBlanksAs(mode);
auto outputPath = String::Format(u"empty_cells_{0}.pptx", mode);
presentation->Save(outputPath, SaveFormat::Pptx);
}
presentation->Dispose();
各出力ファイルは保存前に設定されたモードを保持します:empty_cells_Gap.pptx、empty_cells_Zero.pptx、empty_cells_Span.pptx。1 つのバージョンだけを保存したい場合は、目的のモードを割り当ててプレゼンテーションを 1 回だけ保存してください。
以下の比較は、3 つのファイルすべてで同じデータがどのように表示されるかを示しています。Day 3 はすべてのケースでワークブック上は空です。

可視効果はチャートの種類に依存します。折れ線グラフは 3 つのモードを比較しやすいですが、棒や縦棒グラフは欠損カテゴリを横切る線がないため、Span は上記のような接続セグメントを生成できません。欠損列とゼロ高さの列は見た目が似ることがあります。同様に、マーカーのみの散布図も接続線がありません。すべてのチャート タイプで 3 つの明確な結果が得られるとは限らないため、使用するタイプで出力を確認してください。
シリーズのギャップ幅を設定する
ギャップ幅は隣接するバーまたは列クラスター間のスペースで、バーまたは列幅のパーセンテージで表されます。重なりと同様に、これは個々のシリーズではなく親シリーズ グループに属します。グループ全体に対して 1 回だけ IChartSeriesGroup::set_GapWidth を呼び出します。値を大きくするとクラスター間のスペースが広がり、値を小さくすると密集します。
以下の例はギャップ幅を変更し、最終プレゼンテーションだけを保存します。
#include <cstdint>
#include <DOM/Chart/ChartType.h>
#include <DOM/Chart/IChartData.h>
#include <DOM/Chart/IChartSeries.h>
#include <DOM/Chart/IChartSeriesCollection.h>
#include <DOM/Chart/IChartSeriesGroup.h>
#include <DOM/IChart.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/shared_ptr.h>
using Aspose::Slides::Charts::ChartType;
using Aspose::Slides::Export::SaveFormat;
using Aspose::Slides::Presentation;
const int firstSlideIndex = 0;
const int firstSeriesIndex = 0;
const uint16_t gapWidthPercent = 30;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(firstSlideIndex);
auto chart = slide->get_Shapes()->AddChart(ChartType::StackedColumn, 20.0f, 20.0f, 500.0f, 200.0f);
auto seriesCollection = chart->get_ChartData()->get_Series();
auto series = seriesCollection->idx_get(firstSeriesIndex);
series->get_ParentSeriesGroup()->set_GapWidth(gapWidthPercent);
presentation->Save(u"gap_width_30.pptx", SaveFormat::Pptx);
presentation->Dispose();
結果:

FAQ
どのチャート タイプがデータ シリーズをサポートしていますか?
ChartType 列挙体で表されるすべてのチャート タイプはデータを使用しますが、シリーズの値構造や設定はすべて同じではありません。たとえば、カテゴリ チャートはカテゴリと値を使用し、散布図は X と Y の値を使用し、バブル チャートはバブル サイズを追加します。シリーズ タイプに合ったデータ ポイント作成メソッドを使用してください。重なりやギャップ幅などのオプションは、互換性のある棒または列グループにのみ適用されます。
チャート シリーズ グループとは何ですか?
IChartSeriesGroup は、グループレベルのプロット設定を共有する互換性のあるシリーズを保持します。組み合わせチャートは複数のグループを含むことができるため、あるシリーズを通じて取得したグループを変更しても、必ずしもチャート内のすべてのシリーズが変更されるわけではありません。
新しく作成したチャートは既定データを含みますか?
はい。デフォルトでは、IShapeCollection::AddChart がサンプルのシリーズ、カテゴリ、値を作成します。これらのセルを編集するか、完全にカスタム データ セットを追加する前にシリーズとカテゴリのコレクションをクリアできます。オーバーロードを使用して既定データなしでチャートを作成することも可能です。
チャート オブジェクトはワークブック セルとどのように接続されていますか?
シリーズ名、カテゴリ ラベル、データ ポイント値はすべて IChartDataWorkbook のセルを参照します。参照セルを変更すると、対応するチャート要素が更新されます。カスタム データを構築する際は、カテゴリ行とシリーズ値行が整合するように配置し、各ポイントが意図したカテゴリの下にプロットされるようにしてください。
シリーズ全体ではなく 1 つのポイントだけをクリアするには?
値セルを nullptr に設定して、ポイントのカテゴリ位置は保持しつつ空のポイントにします。IChartDataPointCollection::Clear は、そのシリーズのすべてのポイントを削除したいときだけ使用してください。カテゴリも削除する場合は、すべてのシリーズがカテゴリ コレクションと整合するように更新してください。
空のポイントはどのように表示されますか?
表示はチャート タイプと IChart::get_DisplayBlanksAs の設定に依存します。サポートされているチャートは、空白をギャップ、ゼロ値、または隣接ポイントを接続する形で表示できます。欠損データの意味に合う設定を選択してください。完全な例とビジュアル比較は、空白セルの表示を制御する を参照してください。
負の値はどのように書式設定されますか?
サポートされている棒、縦棒、バブル シリーズの場合、IChartSeries::set_InvertIfNegative を呼び出し、色を IChartSeries::get_InvertedSolidFillColor で設定します。個々のポイントに対しては IChartDataPoint::set_InvertIfNegative で動作を上書きできます。これらのメソッドは書式設定に影響し、数値自体は変更しません。
シリーズとポイントの両方が書式設定されている場合、どちらが優先されますか?
明示的なデータ ポイントの書式設定がそのポイントに対して優先されます。他のポイントは明示的なシリーズ書式設定、またはシリーズ書式が未定義の場合は自動的なチャート スタイルとテーマを使用します。重なりやギャップ幅などのグループ設定はレイアウトに影響し、ポイントレベルの書式設定を上書きしません。
チャートに含められるシリーズ数に上限はありますか?
Aspose.Slides には別個の固定シリーズ数上限はありません。実際には、プレゼンテーション ファイルの制約、利用可能なメモリ、レンダリング時間、チャートの可読性などが実用的な上限を決定します。
列が互いに近すぎる、または遠すぎる場合はどうすればよいですか?
適切な親シリーズ グループに対して IChartSeriesGroup::set_GapWidth を呼び出します。値を大きくするとクラスター間のスペースが広がり、値を小さくするとクラスターが近づきます。