Marcador de Datos de Gráfico
Establecer Marcador de Gráfico
Aspose.Slides para C++ proporciona una API simple para establecer automáticamente el marcador de la serie de gráficos. En la siguiente función, cada serie de gráficos obtendrá automáticamente un símbolo de marcador predeterminado diferente.
El siguiente ejemplo de código muestra cómo establecer automáticamente el marcador de la serie de gráficos.
// 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); | |
Establecer Opciones del Marcador de Gráfico
Los marcadores se pueden establecer en los puntos de datos del gráfico dentro de una serie particular. Para establecer opciones del marcador del gráfico, siga los pasos a continuación:
- Instanciar la clase Presentation.
- Crear el gráfico predeterminado.
- Establecer la imagen.
- Tomar la primera serie de gráficos.
- Agregar un nuevo punto de datos.
- Escribir una presentación en el disco.
En el ejemplo dado a continuación, hemos establecido las opciones del marcador de gráficos a nivel de puntos de datos.
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); | |
Establecer Marcador de Gráfico en el Nivel de Puntos de Datos de la Serie
Ahora, los marcadores se pueden establecer en los puntos de datos del gráfico dentro de una serie particular. Para establecer opciones del marcador del gráfico, siga los pasos a continuación:
- Instanciar la clase Presentation.
- Crear el gráfico predeterminado.
- Establecer la imagen.
- Tomar la primera serie de gráficos.
- Agregar un nuevo punto de datos.
- Escribir una presentación en el disco.
En el ejemplo dado a continuación, hemos establecido las opciones del marcador de gráficos a nivel de puntos de datos.
const String outPath = u"../out/SetMarkerOptionsonSeries_out.pptx";
const String ImagePath = u"../templates/Tulips.jpg";
const String ImagePath2 = u"../templates/aspose - logo.jpg";
//Instanciar la clase Presentation que representa el archivo PPTX
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Acceder a la primera diapositiva
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Agregar gráfico con datos predeterminados
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::LineWithMarkers, 0, 0, 500, 500);
// Estableciendo el índice de la hoja de datos del gráfico
int defaultWorksheetIndex = 0;
// Obtener la hoja de datos del gráfico
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();
// Eliminar series y categorías generadas por defecto
chart->get_ChartData()->get_Series()->Clear();
// Ahora, agregando una nueva 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());
// Obtener la imagen
SharedPtr<IImage> image = Images::FromFile(ImagePath);
SharedPtr<IImage> image2 = Images::FromFile(ImagePath2);
// Agregar imagen a la colección de imágenes de la presentación
SharedPtr<IPPImage> imgx1 = pres->get_Images()->AddImage(image);
SharedPtr<IPPImage> imgx2 = pres->get_Images()->AddImage(image2);
image->Dispose();
image2->Dispose();
// Agregar nuevo punto (1:3) allí.
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);
// Cambiando el marcador de la serie de gráficos
series->get_Marker()->set_Size(15);
// Escribir el archivo de presentación en el disco
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
pres->Dispose();
Aplicar Color a los Puntos de Datos
Puede aplicar color a los puntos de datos en el gráfico utilizando Aspose.Slides para C++. La clase IChartDataPointLevelsManager y IChartDataPointLevel se han agregado para acceder a las propiedades de los niveles de puntos de datos. Este artículo demuestra cómo puede acceder y aplicar color a los puntos de datos en un gráfico.
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); |