パイチャート

パイオブパイおよびバーハイチャートの第二プロットオプション

Aspose.Slides for C++は、パイオブパイまたはバーハイチャートの第二プロットオプションをサポートしています。このトピックでは、Aspose.Slidesを使用してこれらのオプションを指定する方法を例とともに見ていきます。プロパティを指定するために、以下の手順に従ってください。

  1. Presentationクラスのオブジェクトをインスタンス化します。
  2. スライドにチャートを追加します。
  3. チャートの第二プロットオプションを指定します。
  4. プレゼンテーションをディスクに書き出します。

以下の例では、パイオブパイチャートの異なるプロパティを設定しています。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/SecondPlotOptionsforCharts_out.pptx";
//Instantiate Presentation class that represents PPTX file
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add chart with default data
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Pie, 0, 0, 500, 500);
// Take first chart series
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// Set different properties
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true);
series->get_ParentSeriesGroup()->set_SecondPieSize ( 149);
series->get_ParentSeriesGroup()->set_PieSplitBy ( Aspose::Slides::Charts::PieSplitType::ByPercentage);
series->get_ParentSeriesGroup()->set_PieSplitPosition ( 53);
// Write the presentation file to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

自動パイチャートスライスの色を設定する

Aspose.Slides for C++は、自動パイチャートスライスの色を設定するためのシンプルなAPIを提供します。サンプルコードは、上記のプロパティを設定しています。

  1. Presentationクラスのインスタンスを作成します。
  2. 最初のスライドにアクセスします。
  3. デフォルトデータでチャートを追加します。
  4. チャートのタイトルを設定します。
  5. 最初の系列を値を表示するように設定します。
  6. チャートデータシートのインデックスを設定します。
  7. チャートデータのワークシートを取得します。
  8. デフォルトで生成された系列とカテゴリを削除します。
  9. 新しいカテゴリを追加します。
  10. 新しい系列を追加します。

修正したプレゼンテーションをPPTXファイルに書き出します。

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/AutomicPieChartSliceColors_out.pptx";
//Instantiate Presentation class that represents PPTX file
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add chart with default data
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Pie, 0, 0, 500, 500);
// Setting 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 default generated series and categories
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// Add Catrgories
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"First Qtr")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"2nd Qtr")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"3ed Qtr")));
// Now, Adding a new series
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
// Take first chart series
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);
// Now populating series data
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(20)));
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(50)));
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(30)));
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_IsColorVaried(true);
// Write the presentation file to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);