Gráfico de Pastel
Opciones de Segundo Trazado para Gráfico de Pastel de Pastel y Gráfico de Pastel de Barra
Aspose.Slides para C++ ahora soporta opciones de segundo trazado para el gráfico de pastel de pastel o gráfico de pastel de barra. En este tema, veremos con un ejemplo cómo especificar estas opciones usando Aspose.Slides. Para especificar las propiedades, siga los pasos a continuación:
- Instanciar el objeto de la clase Presentation.
- Agregar gráfico en la diapositiva.
- Especificar las opciones de segundo trazado del gráfico.
- Escribir la presentación en el disco.
En el ejemplo dado a continuación, hemos configurado diferentes propiedades del gráfico de pastel de pastel.
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/SecondPlotOptionsforCharts_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::Pie, 0, 0, 500, 500); | |
// Take first chart series | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
// Set different properties | |
series->get_Labels()->get_DefaultDataLabelFormat()->set_ShowValue(true); | |
series->get_ParentSeriesGroup()->set_SecondPieSize ( 149); | |
series->get_ParentSeriesGroup()->set_PieSplitBy ( Aspose::Slides::Charts::PieSplitType::ByPercentage); | |
series->get_ParentSeriesGroup()->set_PieSplitPosition ( 53); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Establecer Colores de Rebanadas de Gráfico de Pastel Automáticos
Aspose.Slides para C++ proporciona una API simple para establecer colores de rebanadas de gráfico de pastel automáticos. El código de muestra aplica la configuración de las propiedades mencionadas anteriormente.
- Crear una instancia de la clase Presentation.
- Acceder a la primera diapositiva.
- Agregar gráfico con datos por defecto.
- Establecer el título del gráfico.
- Establecer la primera serie para mostrar valores.
- Establecer el índice de la hoja de datos del gráfico.
- Obtener la hoja de datos del gráfico.
- Eliminar series y categorías generadas por defecto.
- Agregar nuevas categorías.
- Agregar nuevas series.
Escribir la presentación modificada en un archivo 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/AutomicPieChartSliceColors_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::Pie, 0, 0, 500, 500); | |
// Setting chart Title | |
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Sample Title"); | |
chart->get_ChartTitle()->get_TextFrameForOverriding()->get_TextFrameFormat()->set_CenterText(NullableBool::True); | |
chart->get_ChartTitle()->set_Height(20); | |
chart->set_HasTitle(true); | |
// Delete default generated series and categories | |
chart->get_ChartData()->get_Series()->Clear(); | |
chart->get_ChartData()->get_Categories()->Clear(); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data worksheet | |
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook(); | |
// Add Catrgories | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"First Qtr"))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"2nd Qtr"))); | |
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"3ed Qtr"))); | |
// Now, Adding a new series | |
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type()); | |
// Take first chart series | |
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0); | |
// Now populating series data | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box<double>(20))); | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box<double>(50))); | |
series->get_DataPoints()->AddDataPointForPieSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box<double>(30))); | |
chart->get_ChartData()->get_SeriesGroups()->idx_get(0)->set_IsColorVaried(true); | |
// Write the presentation file to disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |