Diagramm Datenmarker
Diagrammmarker Setzen
Aspose.Slides für C++ bietet eine einfache API, um den Diagrammserienmarker automatisch festzulegen. In der folgenden Funktion erhält jede Diagrammserie automatisch ein unterschiedliches Standardsymbol für den Marker.
Das folgende Codebeispiel zeigt, wie man den Diagrammserienmarker automatisch festlegt.
// 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); | |
Diagrammmarker-Optionen Setzen
Die Marker können an Diagrammdatenpunkten innerhalb einer bestimmten Serie festgelegt werden. Um die Optionen für Diagrammmarker festzulegen, befolgen Sie bitte die folgenden Schritte:
- Erstellen Sie eine Presentation Klasse.
- Erstellen Sie das Standarddiagramm.
- Setzen Sie das Bild.
- Nehmen Sie die erste Diagrammserie.
- Fügen Sie einen neuen Datenpunkt hinzu.
- Schreiben Sie eine Präsentation auf die Festplatte.
Im folgenden Beispiel haben wir die Diagrammmarker-Optionen auf Ebene der Datenpunkte festgelegt.
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); | |
Diagrammmarker auf Ebene der Serien-Datenpunkte Setzen
Jetzt können die Marker an Diagrammdatenpunkten innerhalb einer bestimmten Serie festgelegt werden. Um die Optionen für Diagrammmarker festzulegen, befolgen Sie bitte die folgenden Schritte:
- Erstellen Sie die Präsentationsklasse.
- Erstellen Sie das Standarddiagramm.
- Setzen Sie das Bild.
- Nehmen Sie die erste Diagrammserie.
- Fügen Sie einen neuen Datenpunkt hinzu.
- Schreiben Sie eine Präsentation auf die Festplatte.
Im folgenden Beispiel haben wir die Diagrammmarker-Optionen auf Ebene der Datenpunkte festgelegt.
const String outPath = u"../out/SetMarkerOptionsonSeries_out.pptx";
const String ImagePath = u"../templates/Tulips.jpg";
const String ImagePath2 = u"../templates/aspose - logo.jpg";
//Instanziieren Sie die Präsentationsklasse, die die PPTX-Datei darstellt
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Zugriff auf die erste Folie
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Fügen Sie ein Diagramm mit Standarddaten hinzu
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::LineWithMarkers, 0, 0, 500, 500);
// Festlegen des Index des Diagrammdatenblatts
int defaultWorksheetIndex = 0;
// Abrufen des Diagrammdatenarbeitsblatts
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// Löschen der standardmäßig generierten Serien und Kategorien
chart->get_ChartData()->get_Series()->Clear();
// Jetzt, Hinzufügen einer neuen Serie
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<System::String>(u"Serie 1")), chart->get_Type());
// Holen Sie sich das Bild
SharedPtr<IImage> image = Images::FromFile(ImagePath);
SharedPtr<IImage> image2 = Images::FromFile(ImagePath2);
// Bild zur Bildersammlung der Präsentation hinzufügen
SharedPtr<IPPImage> imgx1 = pres->get_Images()->AddImage(image);
SharedPtr<IPPImage> imgx2 = pres->get_Images()->AddImage(image2);
image->Dispose();
image2->Dispose();
// Neuen Punkt (1:3) hinzufügen.
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);
// Ändern des Diagrammserienmarkers
series->get_Marker()->set_Size(15);
// Schreiben Sie die Präsentationsdatei auf die Festplatte
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
pres->Dispose();
Farbe auf Datenpunkte Anwenden
Sie können Farbe auf Datenpunkte im Diagramm anwenden, indem Sie Aspose.Slides für C++ verwenden. IChartDataPointLevelsManager und IChartDataPointLevel Klassen wurden hinzugefügt, um Zugriff auf die Eigenschaften von Datenpunkt-Ebenen zu erhalten. Dieser Artikel zeigt, wie Sie auf die Datenpunkte zugreifen und Farbe darauf anwenden können.
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); |