علامة بيانات الرسم البياني
تعيين علامة الرسم البياني
يقدم Aspose.Slides لـ C++ واجهة برمجة تطبيقات بسيطة لتعيين علامة سلسلة الرسم البياني تلقائيًا. في الميزة التالية، ستحصل كل سلسلة رسم بياني على رمز علامة افتراضي مختلف تلقائيًا.
يوضح مثال الكود أدناه كيفية تعيين علامة سلسلة الرسم البياني تلقائيًا.
// 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 class.
- إنشاء الرسم البياني الافتراضي.
- تعيين الصورة.
- أخذ أول سلسلة رسم بياني.
- إضافة نقطة بيانات جديدة.
- كتابة العرض إلى القرص.
في المثال المعطى أدناه، قمنا بتعيين خيارات علامة الرسم البياني على مستوى نقاط البيانات.
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 class.
- إنشاء الرسم البياني الافتراضي.
- تعيين الصورة.
- أخذ أول سلسلة رسم بياني.
- إضافة نقطة بيانات جديدة.
- كتابة العرض إلى القرص.
في المثال المعطى أدناه، قمنا بتعيين خيارات علامة الرسم البياني على مستوى نقاط البيانات.
const String outPath = u"../out/SetMarkerOptionsonSeries_out.pptx";
const String ImagePath = u"../templates/Tulips.jpg";
const String ImagePath2 = u"../templates/aspose - logo.jpg";
//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 the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// Delete default generated series and categories
chart->get_ChartData()->get_Series()->Clear();
// Now, Adding a new series
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
// Get the picture
SharedPtr<IImage> image = Images::FromFile(ImagePath);
SharedPtr<IImage> image2 = Images::FromFile(ImagePath2);
// Add image to presentation's images collection
SharedPtr<IPPImage> imgx1 = pres->get_Images()->AddImage(image);
SharedPtr<IPPImage> imgx2 = pres->get_Images()->AddImage(image2);
image->Dispose();
image2->Dispose();
// Add new point (1:3) there.
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);
// Changing the chart series marker
series->get_Marker()->set_Size(15);
// Write the presentation file to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
pres->Dispose();
تطبيق اللون على نقاط البيانات
يمكنك تطبيق اللون على نقاط البيانات في الرسم البياني باستخدام Aspose.Slides لـ C++. تم إضافة IChartDataPointLevelsManager و IChartDataPointLevel classes للوصول إلى خصائص مستويات نقاط البيانات. توضح هذه المقالة كيفية الوصول إلى نقاط البيانات وتطبيق اللون عليها في الرسم البياني.
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); |