Crear gráficos en presentaciones PPT con C++
Cree gráficos en presentaciones PPT con las API de servidor de Aspose.Slides for C++ sin Microsoft PowerPoint.
Crear gráficos PPT con C++
Use Aspose.Slides for C++ para crear gráficos en presentaciones PPT. Instale el paquete desde NuGet o use el siguiente comando en la Consola del Administrador de paquetes.
Comando
PM> Install-Package Aspose.Slides.CppCrear un gráfico en PPT – C++
auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
// Add a chart with default data.
auto chart = slide->get_Shapes()->AddChart(ChartType::ClusteredColumn, 0, 0, 500, 500);
// Set the index of the chart data sheet.
int defaultWorksheetIndex = 0;
// Get the chart data workbook.
auto chartDataWorkbook = chart->get_ChartData()->get_ChartDataWorkbook();
// Set the 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 the default generated series and categories.
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
// Add series.
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box(String(u"Series 1"))), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box(String(u"Series 2"))), chart->get_Type());
// Add categories.
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box(String(u"Category 1"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box(String(u"Category 2"))));
chart->get_ChartData()->get_Categories()->Add(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box(String(u"Category 3"))));
// Take the first chart series.
auto series = chart->get_ChartData()->get_Series()->idx_get(0);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box(20)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box(50)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box(30)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Blue());
// Take the second chart series.
series = chart->get_ChartData()->get_Series()->idx_get(1);
// Populate series data.
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box(30)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box(10)));
series->get_DataPoints()->AddDataPointForBarSeries(chartDataWorkbook->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box(60)));
// Set the fill color for the series.
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(Color::get_Orange());
// Show the category name for the first label.
auto dataLabel = series->get_DataPoints()->idx_get(0)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowCategoryName(true);
dataLabel = series->get_DataPoints()->idx_get(1)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
// Show the value for the third label.
dataLabel = series->get_DataPoints()->idx_get(2)->get_Label();
dataLabel->get_DataLabelFormat()->set_ShowValue(true);
dataLabel->get_DataLabelFormat()->set_ShowSeriesName(true);
dataLabel->get_DataLabelFormat()->set_Separator(u"/");
// Save the PPT file.
presentation->Save(u"column_chart.ppt", SaveFormat::Ppt);
presentation->Dispose();Cómo crear gráficos en archivos PPT con C++
Cree un gráfico en una presentación PPT con Aspose.Slides for C++ en unas pocas líneas de código.
- Cree un objeto
Presentation. - Acceda a la primera diapositiva.
- Agregue un gráfico con datos predeterminados.
- Establezca el índice de la hoja de datos del gráfico.
- Obtenga el libro de datos del gráfico.
- Establezca el título del gráfico.
- Elimine las series y categorías generadas de forma predeterminada.
- Agregue series y categorías.
- Tome la primera serie del gráfico y rellene sus datos.
- Establezca el color de relleno de la serie.
- Muestre el nombre de categoría, el nombre de serie y el valor en las etiquetas de datos de la segunda serie.
- Guarde el archivo PPT.
Requisitos del sistema
Aspose.Slides for C++ es compatible con las principales plataformas y sistemas operativos. Asegúrese de que su entorno cumpla los siguientes requisitos previos.
- Microsoft Windows, Linux, macOS u otro sistema operativo compatible con el entorno de ejecución de C++ admitido.
- La biblioteca Aspose.Slides for C++ referenciada en su proyecto.
Creado con Aspose.Slides
Crear gráficos PPT en línea
La aplicación gratuita Aspose.Slides Chart está creada con Aspose.Slides for C++, la misma API que el código anterior. Ábrala y descubra lo que la API puede hacer con sus propios archivos PPT.
- Funciona en su navegador, sin instalar nada.
- Vea cómo Aspose.Slides crea gráficos antes de escribir código.
- Cree un gráfico a partir de datos de Excel o de una tabla.
- Descárguelo como archivo PPT o como imagen.
Qué es PPT Formato de archivo
Un archivo PPT contiene un conjunto de diapositivas para una presentación. Usa el formato de archivo binario de Microsoft PowerPoint 97-2003. Un archivo PPT puede contener texto, viñetas, imágenes, multimedia y otros objetos OLE incrustados. Microsoft introdujo el formato PPTX, más reciente, en PowerPoint 2007. PPTX se basa en Office Open XML y difiere del antiguo formato binario. Otras aplicaciones, como OpenOffice Impress y Apple Keynote, también pueden crear archivos PPT.
Otros formatos compatibles para gráficos
Con C++, también puede crear gráficos en otros formatos.