C++ で PPTX プレゼンテーションにグラフを作成
Microsoft PowerPoint なしで、サーバー側の Aspose.Slides for C++ API を使用して PPTX プレゼンテーションにグラフを作成します。
C++ で PPTX グラフを作成
Aspose.Slides for C++ を使用して、PPTX プレゼンテーションにグラフを作成します。 NuGet からパッケージをインストールするか、パッケージ マネージャー コンソールで次のコマンドを使用してください。
コマンド
PM> Install-Package Aspose.Slides.CppPPTX にグラフを作成 – C++
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
// Add a chart with default data.
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 0, 0, 500, 500);
// Set the index of the chart data sheet.
int defaultWorksheetIndex = 0;
// Get the chart data workbook.
auto chartDataWorkbook = chart->get_ChartData()->get_ChartDataWorkbook();
// Set the chart title.
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Sample Title");
chart->get_ChartTitle()->get_TextFrameForOverriding()->get_TextFrameFormat()->set_CenterText(NullableBool::True);
chart->get_ChartTitle()->set_Height(20);
chart->set_HasTitle(true);
// Delete the default generated series and categories.
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// Add series.
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box(String(u"Series 1"))), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box(String(u"Series 2"))), chart->get_Type());
// Add categories.
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box(String(u"Category 1"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box(String(u"Category 2"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box(String(u"Category 3"))));
// Take the first chart series.
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box(20)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box(50)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box(30)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Blue());
// Take the second chart series.
series = chart->get_ChartData()->get_Series()->idx_get(1);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box(30)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box(10)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box(60)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Orange());
// Show the category name for the first label.
auto dataLabel = series->get_DataPoints()->idx_get(0)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowCategoryName(true);
dataLabel = series->get_DataPoints()->idx_get(1)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
// Show the value for the third label.
dataLabel = series->get_DataPoints()->idx_get(2)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowValue(true);
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
dataLabel->get_DataLabelFormat()->set_Separator(u"/");
// Save the PPTX file.
presentation->Save(u"column_chart.pptx", SaveFormat::Pptx);
presentation->Dispose();C++ で PPTX ファイルにグラフを作成する方法
Aspose.Slides for C++ を使用すると、数行のコードで PPTX プレゼンテーションにグラフを作成できます。
Presentationオブジェクトを作成します。- 最初のスライドにアクセスします。
- 既定のデータを持つグラフを追加します。
- グラフのデータ シートのインデックスを設定します。
- グラフのデータ ブックを取得します。
- グラフのタイトルを設定します。
- 既定で生成された系列とカテゴリを削除します。
- 系列とカテゴリを追加します。
- グラフの最初の系列を取得し、データを入力します。
- 系列の塗りつぶしの色を設定します。
- 2 番目の系列のデータ ラベルに、カテゴリ名、系列名、値を表示します。
- PPTX ファイルを保存します。
システム要件
Aspose.Slides for C++ は主要なプラットフォームとオペレーティング システムをサポートしています。環境が次の前提条件を満たしていることを確認してください。
- サポート対象の C++ ランタイムを備えた Microsoft Windows、Linux、macOS、またはその他の互換 OS。
- プロジェクトで参照されている Aspose.Slides for C++ ライブラリ。
Aspose.Slides で構築
PPTX グラフをオンラインで作成
無料の Aspose.Slides Chart アプリは、上記のコードと同じ API である Aspose.Slides for C++ で構築されています。アプリを開いて、ご自身の PPTX ファイルで API に何ができるかをお確かめください。
- ブラウザーで動作し、インストールは不要です。
- コードを書く前に、Aspose.Slides がグラフを作成するしくみを確認できます。
- Excel またはテーブルのデータからグラフを作成します。
- PPTX ファイルまたは画像としてダウンロードします。
PPTX ファイル形式とは
PPTX ファイルは、Microsoft PowerPoint やその他のプレゼンテーション アプリで作成されたプレゼンテーション ファイルです。従来のバイナリ PPT 形式とは異なり、PPTX は Office Open XML に基づいています。プレゼンテーションは、テキスト、画像、書式、アニメーションなどのメディアを含むスライドで構成されます。スライドは、カスタム設定のスライド ショーとして聴衆に表示されます。
グラフでサポートされるその他の形式
C++ を使用すると、他の形式でもグラフを作成できます。