チャートの書式設定
チャートエンティティの書式設定
Aspose.Slides for C++は、開発者がスライドにカスタムチャートをゼロから追加できるようにします。この記事では、チャートカテゴリと値軸を含むさまざまなチャートエンティティの書式設定方法を説明します。
Aspose.Slides for C++は、さまざまなチャートエンティティを管理し、カスタム値を使用して書式設定するためのシンプルなAPIを提供します。
- Presentationクラスのインスタンスを作成します。
- インデックスでスライドの参照を取得します。
- デフォルトデータを持つチャートを追加し、希望する任意のタイプ(この例ではChartType.LineWithMarkersを使用します)を指定します。
- チャートの値軸にアクセスし、以下のプロパティを設定します。
- 値軸の主グリッド線のためのライン形式を設定します。
- 値軸の副グリッド線のためのライン形式を設定します。
- 値軸のための数値形式を設定します。
- 値軸の最小、最大、主および副単位を設定します。
- 値軸データのためのテキストプロパティを設定します。
- 値軸のためのタイトルを設定します。
- 値軸のライン形式を設定します。
- チャートのカテゴリ軸にアクセスし、以下のプロパティを設定します。
- カテゴリ軸の主グリッド線のためのライン形式を設定します。
- カテゴリ軸の副グリッド線のためのライン形式を設定します。
- カテゴリ軸データのためのテキストプロパティを設定します。
- カテゴリ軸のためのタイトルを設定します。
- カテゴリ軸のためのラベル位置を設定します。
- カテゴリ軸ラベルの回転角度を設定します。
- チャートの凡例にアクセスし、それらのためのテキストプロパティを設定します。
- チャートの凡例が重ならないように表示するように設定します。
- チャートの副値軸にアクセスし、以下のプロパティを設定します。
- 副値軸を有効にします。
- 副値軸のためのライン形式を設定します。
- 副値軸のための数値形式を設定します。
- 副値軸の最小、最大、主および副単位を設定します。
- まず副値軸にチャートシリーズをプロットします。
- チャートのバックウォールに塗りつぶし色を設定します。
- チャートのプロットエリアに塗りつぶし色を設定します。
- 修正されたプレゼンテーションを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/FormatChart_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(Aspose::Slides::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()->get_SolidFillColor()->set_Color(System::Drawing:: Color::get_DarkGreen()); | |
SharedPtr<FontData> fontData = MakeObject<FontData>(u"Times New Roman"); | |
//FontDataFactory.CreateFontData //txtVal->set_LatinFont(MakeObject<IFontData>(u"Times New Roman")); | |
txtVal->set_LatinFont(fontData); | |
// 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()->set_FillType( FillType::Solid) ; | |
txtCat->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue()); | |
SharedPtr<FontData> Arial = MakeObject<FontData>(u"Arial"); | |
txtCat->set_LatinFont(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()->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Orange()); | |
chart->get_Floor()->get_Format()->get_Fill()->set_FillType(FillType::Solid); | |
chart->get_Floor()->get_Format()->get_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()->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_LightCyan()); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
チャートのためのフォントプロパティを設定する
Aspose.Slides for C++は、チャートのフォントに関連するプロパティの設定をサポートしています。以下の手順に従って、チャートのフォントプロパティを設定してください。
- Presentationクラスのオブジェクトをインスタンス化します。
- スライドにチャートを追加します。
- フォントの高さを設定します。
- 修正されたプレゼンテーションを保存します。
以下にサンプル例を示します。
// The path to the documents directory. | |
const String outPath = u"../out/FontPropertiesForChart.pptx"; | |
//Instantiate Presentation class that represents PPTX file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
SharedPtr<IChart> chart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ClusteredColumn, 100, 100, 500, 400); | |
chart->get_TextFormat()->get_PortionFormat()->set_FontHeight(20); | |
chart->get_ChartData()->get_Series()->idx_get(0)->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true); | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
チャートデータテーブルのためのフォントプロパティを設定する
Aspose.Slides for C++は、シリーズの色におけるカテゴリの色を変更するためのサポートを提供します。
- 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/SettingFontPropertiesForChartDataTable_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::ClusteredColumn, 0, 0, 500, 500); | |
//Setting chart data table | |
chart->set_HasDataTable(true); | |
//Setting font properties | |
chart->get_ChartDataTable()->get_TextFormat()->get_PortionFormat()->set_FontBold (NullableBool::True); | |
chart->get_ChartDataTable()->get_TextFormat()->get_PortionFormat()->set_FontHeight ( 20); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
チャートエリアの角を丸く設定する
Aspose.Slides for C++は、チャートエリアの設定をサポートします。IChart.HasRoundedCornersおよびChart.HasRoundedCornersプロパティがAspose.Slidesに追加されました。
- Presentationクラスのオブジェクトをインスタンス化します。
- スライドにチャートを追加します。
- チャートの塗りつぶしタイプと色を設定します。
- 角丸プロパティをTrueに設定します。
- 修正されたプレゼンテーションを保存します。
以下にサンプル例を示します。
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/SettingChartAreaRoundedBorders_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::ClusteredColumn, 0, 0, 500, 500); | |
chart->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid); | |
chart->get_LineFormat()->set_Style(LineStyle::Single); | |
chart->set_HasRoundedCorners ( true); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
チャートデータの数値を設定する
Aspose.Slides for C++は、チャートデータ形式を管理するためのシンプルなAPIを提供します。
1. Presentation クラスのインスタンスを作成します。
- インデックスでスライドの参照を取得します。
- デフォルトデータを持つチャートを追加し、希望する任意のタイプ(この例ではChartType.ClusteredColumnを使用します)を指定します。
- 可能なプリセット値からプリセットの数値形式を設定します。
- 各チャートシリーズのチャートデータセルを検索し、チャートデータの数値形式を設定します。
- プレゼンテーションを保存します。
- カスタム数値形式を設定します。
- 各チャートシリーズ内のチャートデータセルを検索し、異なるチャートデータの数値形式を設定します。
- プレゼンテーションを保存します。
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/NumberFormat_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::ClusteredColumn, 0, 0, 500, 500); | |
// Accessing the chart series collection | |
SharedPtr<IChartSeriesCollection> seriesCollection = chart->get_ChartData()->get_Series(); | |
// Setting the preset number format | |
// Traverse through every chart series | |
for(int i = 0; i < seriesCollection->get_Count();i++) | |
{ | |
auto series = seriesCollection->idx_get(i); | |
// Traverse through every data cell in series | |
for(int j=0;j<series->get_DataPoints()->get_Count();j++) | |
{ | |
auto cell = series->get_DataPoints()->idx_get(j); | |
// Setting the number format | |
cell->get_Value()->get_AsCell()->set_PresetNumberFormat (10); //0.00% | |
} | |
} | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
使用可能なプリセットの数値形式とそのプリセットインデックスが以下に示されています。 |
---|
0 | 一般 |
---|---|
1 | 0 |
2 | 0.00 |
3 | #,##0 |
4 | #,##0.00 |
5 | $#,##0;$-#,##0 |
6 | $#,##0;Red$-#,##0 |
7 | $#,##0.00;$-#,##0.00 |
8 | $#,##0.00;Red$-#,##0.00 |
9 | 0% |
10 | 0.00% |
11 | 0.00E+00 |
12 | # ?/? |
13 | # / |
14 | m/d/yy |
15 | d-mmm-yy |
16 | d-mmm |
17 | mmm-yy |
18 | h:mm AM/PM |
19 | h:mm:ss AM/PM |
20 | h:mm |
21 | h:mm:ss |
22 | m/d/yy h:mm |
37 | #,##0;-#,##0 |
38 | #,##0;Red-#,##0 |
39 | #,##0.00;-#,##0.00 |
40 | #,##0.00;Red-#,##0.00 |
41 | _ * #,##0_ ;_ * “_ ;_ @_ |
42 | _ $* #,##0_ ;_ $* “_ ;_ @_ |
43 | _ * #,##0.00_ ;_ * “??_ ;_ @_ |
44 | _ $* #,##0.00_ ;_ $* “??_ ;_ @_ |
45 | mm:ss |
46 | h :mm:ss |
47 | mm:ss.0 |
48 | ##0.0E+00 |
49 | @ |