チャートデータマーカー
チャートマーカーの設定
Aspose.Slides for C++ は、チャート系列のマーカーを自動的に設定するためのシンプルなAPIを提供します。次の機能では、各チャート系列が自動的に異なるデフォルトマーカーシンボルを取得します。
以下のコード例は、チャート系列のマーカーを自動的に設定する方法を示しています。
// The path to the documents directory. | |
const String outPath = u"../out/DefaultMarkersInChart.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Accessing the first slide in presentation | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::LineWithMarkers, 10, 10, 400, 400); | |
chart->get_ChartData()->get_Series()->Clear(); | |
chart->get_ChartData()->get_Categories()->Clear(); | |
System::SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook(); | |
chart->get_ChartData()->get_Series()->Add(fact->GetCell(0,0,1, System::ObjectExt::Box<System::String>(u"Category 1")),chart->get_Type()); | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(0, 1, 0, ObjectExt::Box<System::String>(u"C1"))); | |
series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 1, 1, System::ObjectExt::Box<int32_t>(24))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(0, 2, 0, ObjectExt::Box<System::String>(u"C2"))); | |
series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 2, 1, System::ObjectExt::Box<int32_t>(23))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(0, 3, 0, ObjectExt::Box<System::String>(u"C3"))); | |
series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 3, 1, System::ObjectExt::Box<int32_t>(-10))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(0, 4, 0, ObjectExt::Box<System::String>(u"C4"))); | |
series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 4, 1, nullptr)); | |
chart->get_ChartData()->get_Series()->Add(fact->GetCell(0, 0, 2, ObjectExt::Box<System::String>(u"Series 2")), chart->get_Type()); | |
//Take second chart series | |
SharedPtr<IChartSeries> series2 = chart->get_ChartData()->get_Series()->idx_get(1); | |
//Now populating series data | |
series2->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 1, 2, System::ObjectExt::Box<int32_t>(30))); | |
series2->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 2, 2, System::ObjectExt::Box<int32_t>(10))); | |
series2->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 3, 2, System::ObjectExt::Box<int32_t>(60))); | |
series2->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(0, 4, 2, System::ObjectExt::Box<int32_t>(40))); | |
chart->set_HasLegend(true); | |
chart->get_Legend()->set_Overlay(false); | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
チャートマーカーオプションの設定
マーカーは、特定の系列内のチャートデータポイントに設定できます。チャートマーカーオプションを設定するには、以下の手順に従ってください。
- Presentation クラスをインスタンス化します。
- デフォルトチャートを作成します。
- 画像を設定します。
- 最初のチャート系列を取得します。
- 新しいデータポイントを追加します。
- プレゼンテーションをディスクに書き込みます。
以下の例では、データポイントレベルでチャートマーカーオプションを設定しました。
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/MarkerOptions_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::LineWithMarkers, 0, 0, 500, 500); | |
// Setting Chart Titile | |
chart->set_HasTitle(true); | |
chart->get_ChartTitle()->AddTextFrameForOverriding(u""); | |
SharedPtr<IPortion> chartTitle = chart->get_ChartTitle()->get_TextFrameForOverriding()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0); | |
chartTitle->set_Text(u"Sample Chart"); | |
chartTitle->get_PortionFormat()->get_FillFormat()->set_FillType(FillType::Solid); | |
chartTitle->get_PortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Gray()); | |
chartTitle->get_PortionFormat()->set_FontHeight(20); | |
chartTitle->get_PortionFormat()->set_FontBold(NullableBool::True); | |
chartTitle->get_PortionFormat()->set_FontItalic(NullableBool::True); | |
// Setting Major grid lines format for value axis | |
chart->get_Axes()->get_VerticalAxis()->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid); | |
chart->get_Axes()->get_VerticalAxis()->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue()); | |
chart->get_Axes()->get_VerticalAxis()->get_MajorGridLinesFormat()->get_Line()->set_Width(5); | |
chart->get_Axes()->get_VerticalAxis()->get_MajorGridLinesFormat()->get_Line()->set_DashStyle(LineDashStyle::DashDot); | |
// Setting Minor grid lines format for value axis | |
chart->get_Axes()->get_VerticalAxis()->get_MinorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid); | |
chart->get_Axes()->get_VerticalAxis()->get_MinorGridLinesFormat->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red()); | |
chart->get_Axes()->get_VerticalAxis()->get_MinorGridLinesFormat->get_Line()->set_Width(3); | |
// Setting value axis number format | |
chart->get_Axes()->get_VerticalAxis()->set_IsNumberFormatLinkedToSource(false); | |
chart->get_Axes()->get_VerticalAxis()->set_DisplayUnit(DisplayUnitType::Thousands); | |
chart->get_Axes()->get_VerticalAxis()->set_NumberFormat(u"0.0%"); | |
// Setting chart maximum, minimum values | |
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMajorUnit(false); | |
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMaxValue(false); | |
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMinorUnit(false); | |
chart->get_Axes()->get_VerticalAxis()->set_IsAutomaticMinValue(false); | |
chart->get_Axes()->get_VerticalAxis()->set_MaxValue(15); | |
chart->get_Axes()->get_VerticalAxis()->set_MinValue(-2); | |
chart->get_Axes()->get_VerticalAxis()->set_MinorUnit(0.5); | |
chart->get_Axes()->get_VerticalAxis()->set_MajorUnit(2.0); | |
// Setting Value Axis Text Properties | |
SharedPtr<IChartPortionFormat> txtVal = chart->get_Axes()->get_VerticalAxis()->get_TextFormat()->get_PortionFormat(); | |
txtVal->set_FontBold(NullableBool::True); | |
txtVal->set_FontHeight(16); | |
txtVal->set_FontItalic(NullableBool::True); | |
txtVal->get_FillFormat()->set_FillType(FillType::Solid); | |
txtVal->get_FillFormat.SolidFillColor.Color(System::Drawing::Color::get_DarkGreen()); | |
//SharedPtr<IFontData> fontData = MakeObject<IFontData>(L"Times New Roman"); | |
txtVal->set_LatinFont(MakeObject<IFontData>(u"Times New Roman")); | |
// Setting value axis title | |
chart->get_Axes()->get_VerticalAxis()->set_HasTitle(true); | |
chart->get_Axes()->get_VerticalAxis()->get_Title->AddTextFrameForOverriding(u""); | |
SharedPtr<IPortion> valtitle = chart->get_Axes()->get_VerticalAxis()->get_Title()->get_TextFrameForOverriding()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0); | |
valtitle->set_Text(u"Primary Axis"); | |
valtitle->get_PortionFormat()->get_FillFormat()->set_FillType(FillType::Solid); | |
valtitle->get_PortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Gray()); | |
valtitle->get_PortionFormat()->set_FontHeight(20); | |
valtitle->get_PortionFormat()->set_FontBold(NullableBool::True); | |
valtitle->get_PortionFormat()->set_FontItalic(NullableBool::True); | |
// Setting Major grid lines format for Category axis | |
chart->get_Axes()->get_HorizontalAxis()->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid); | |
chart->get_Axes()->get_HorizontalAxis()->get_MajorGridLinesFormat()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Green()); | |
chart->get_Axes()->get_HorizontalAxis()->get_MajorGridLinesFormat()->get_Line()->set_Width(5); | |
// Setting Minor grid lines format for Category axis | |
chart->get_Axes()->get_HorizontalAxis()->get_MinorGridLinesFormat()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid); | |
chart->get_Axes()->get_HorizontalAxis()->get_MinorGridLinesFormat->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Yellow()); | |
chart->get_Axes()->get_HorizontalAxis()->get_MinorGridLinesFormat->get_Line()->set_Width(3); | |
// Setting Category Axis Text Properties | |
SharedPtr<IChartPortionFormat> txtCat = chart->get_Axes()->get_HorizontalAxis()->get_TextFormat()->get_PortionFormat(); | |
txtCat->set_FontBold(NullableBool::True); | |
txtCat->set_FontHeight(16); | |
txtCat->set_FontItalic(NullableBool::True); | |
txtCat->get_FillFormat->se_FillType(FillType::Solid); | |
txtCat->get_FillFormat.get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue()); | |
txtCat->set_LatinFont(MakeObject<IFontData>(u"Arial")); | |
// Setting Category Titile | |
chart->get_Axes()->get_HorizontalAxis()->set_HasTitle(true); | |
chart->get_Axes()->get_HorizontalAxis()->get_Title()->AddTextFrameForOverriding(u""); | |
SharedPtr<IPortion> catTitle = chart->get_Axes()->get_HorizontalAxis()->get_Title()->get_TextFrameForOverriding()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0); | |
catTitle->set_Text(u"Sample Category"); | |
catTitle->get_PortionFormat->get_FillFormat->set_FillType(FillType::Solid); | |
catTitle->get_PortionFormat->get_FillFormat->get_SolidFillColor->set_Color(System::Drawing::Color::get_Gray()); | |
catTitle->get_PortionFormat->set_FontHeight(20); | |
catTitle->get_PortionFormat->set_FontBold(NullableBool::True); | |
catTitle->get_PortionFormat->set_FontItalic(NullableBool::True); | |
// Setting category axis lable position | |
chart->get_Axes()->get_HorizontalAxis()->set_TickLabelPosition(TickLabelPositionType::Low); | |
// Setting category axis lable rotation angle | |
chart->get_Axes()->get_HorizontalAxis()->set_TickLabelRotationAngle(45); | |
// Setting Legends Text Properties | |
SharedPtr<IChartPortionFormat> txtleg = chart->get_Legend->get_TextFormat()->get_PortionFormat(); | |
txtleg->set_FontBold(NullableBool::True); | |
txtleg->set_FontHeight(16); | |
txtleg->set_FontItalic = NullableBool::True; | |
txtleg->get_FillFormat->set_FillType(FillType::Solid); | |
txtleg->get_FillFormat->get_SolidFillColor->set_Color(System::Drawing::Color::get_DarkRed()); | |
// Set show chart legends without overlapping chart | |
chart->get_Legend()->set_Overlay(true); | |
// Ploting first series on secondary value axis | |
// Chart.ChartData.Series[0].PlotOnSecondAxis = true; | |
// Setting chart back wall color | |
chart->get_BackWall->set_Thickness(1); | |
chart->get_BackWall()->get_Format()->get_Fill()->set_FillType(FillType::Solid); | |
chart->get_BackWall.Format.Fill->get_SolidFillColor->set_Color(System::Drawing::Color::get_Orange()); | |
chart->get_Floor->get_Format()->get_Fill()->set_FillType(FillType::Solid); | |
chart->get_Floor.Format.Fill->get_SolidFillColor->set_Color(System::Drawing::Color::get_Red()); | |
// Setting Plot area color | |
chart->get_PlotArea->get_Format()->get_Fill()->set_FillType(FillType::Solid); | |
chart->get_PlotArea.Format.Fill->get_SolidFillColor->set_Color(System::Drawing::Color::get_LightCyan()); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
系列データポイントレベルでのチャートマーカーの設定
現在、マーカーは、特定の系列内のチャートデータポイントに設定できます。チャートマーカーオプションを設定するには、以下の手順に従ってください。
- Presentation クラスをインスタンス化します。
- デフォルトチャートを作成します。
- 画像を設定します。
- 最初のチャート系列を取得します。
- 新しいデータポイントを追加します。
- プレゼンテーションをディスクに書き込みます。
以下の例では、データポイントレベルでチャートマーカーオプションを設定しました。
const String outPath = u"../out/SetMarkerOptionsonSeries_out.pptx";
const String ImagePath = u"../templates/Tulips.jpg";
const String ImagePath2 = u"../templates/aspose - logo.jpg";
//PPTXファイルを表すPresentationクラスをインスタンス化
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// 最初のスライドにアクセス
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// デフォルトデータを持つチャートを追加
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::LineWithMarkers, 0, 0, 500, 500);
// チャートデータシートのインデックスを設定
int defaultWorksheetIndex = 0;
// チャートデータワークブックの取得
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// デフォルトで生成された系列とカテゴリを削除
chart->get_ChartData()->get_Series()->Clear();
// 新しい系列を追加
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<System::String>(u"系列 1")), chart->get_Type());
// 画像を取得
SharedPtr<IImage> image = Images::FromFile(ImagePath);
SharedPtr<IImage> image2 = Images::FromFile(ImagePath2);
// プレゼンテーションの画像コレクションに画像を追加
SharedPtr<IPPImage> imgx1 = pres->get_Images()->AddImage(image);
SharedPtr<IPPImage> imgx2 = pres->get_Images()->AddImage(image2);
image->Dispose();
image2->Dispose();
// (1:3)の新しい点を追加
SharedPtr<IChartDataPoint> point = series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(4.5)));
point->get_Marker()->get_Format()->get_Fill()->set_FillType(FillType::Picture);
point->get_Marker()->get_Format()->get_Fill()->get_PictureFillFormat()->get_Picture()->set_Image(imgx1);
point = series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(2.5)));
point->get_Marker()->get_Format()->get_Fill()->set_FillType(FillType::Picture);
point->get_Marker()->get_Format()->get_Fill()->get_PictureFillFormat()->get_Picture()->set_Image(imgx2);
point = series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(3.5)));
point->get_Marker()->get_Format()->get_Fill()->set_FillType(FillType::Picture);
point->get_Marker()->get_Format()->get_Fill()->get_PictureFillFormat()->get_Picture()->set_Image(imgx1);
point = series->get_DataPoints()->AddDataPointForLineSeries(fact->GetCell(defaultWorksheetIndex, 4, 1, ObjectExt::Box<double>(4.5)));
point->get_Marker()->get_Format()->get_Fill()->set_FillType(FillType::Picture);
point->get_Marker()->get_Format()->get_Fill()->get_PictureFillFormat()->get_Picture()->set_Image(imgx2);
// チャート系列のマーカーを変更
series->get_Marker()->set_Size(15);
// プレゼンテーションファイルをディスクに書き込む
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
pres->Dispose();
データポイントに色を適用
Aspose.Slides for C++を使用して、チャート内のデータポイントに色を適用できます。IChartDataPointLevelsManagerと**IChartDataPointLevel**クラスが追加され、データポイントレベルのプロパティにアクセスできるようになりました。この記事では、チャート内のデータポイントにアクセスして色を適用する方法を示します。
const String outPath = u"../out/AddColorToDataPoints.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(); | |
System::SharedPtr<IChart> chart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::Sunburst, 100.0f, 100.0f, 450.0f, 400.0f); | |
System::SharedPtr<IChartDataPointCollection> dataPoints = chart->get_ChartData()->get_Series()->idx_get(0)->get_DataPoints(); | |
dataPoints->idx_get(3)->get_DataPointLevels()->idx_get(0)->get_Label()->get_DataLabelFormat()->set_ShowValue(true); | |
System::SharedPtr<IDataLabel> branch1Label = dataPoints->idx_get(0)->get_DataPointLevels()->idx_get(2)->get_Label(); | |
branch1Label->get_DataLabelFormat()->set_ShowCategoryName(false); | |
branch1Label->get_DataLabelFormat()->set_ShowSeriesName(true); | |
branch1Label->get_DataLabelFormat()->get_TextFormat()->get_PortionFormat()->get_FillFormat()->set_FillType(Aspose::Slides::FillType::Solid); | |
branch1Label->get_DataLabelFormat()->get_TextFormat()->get_PortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Yellow()); | |
System::SharedPtr<IFormat> steam4Format = dataPoints->idx_get(9)->get_DataPointLevels()->idx_get(1)->get_Format(); | |
steam4Format->get_Fill()->set_FillType(Aspose::Slides::FillType::Solid); | |
steam4Format->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::FromArgb(255, 0, 176, 240)); | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |