PNG JPG BMP TIFF PPTX
Aspose.Slides  for C++

Create Charts in PPTX Presentations Using C++

Create PPTX presentation charts using server-side Aspose.Slides for C++ APIs without Microsoft PowerPoint.

Create PPTX File Charts Using C++

To create charts in a PPTX file, use

Aspose.Slides for C++

API, a feature-rich and easy-to-use presentation manipulation API for C++. You can download its latest version directly, just open

NuGet

package manager, search for Aspose.Slides.Cpp and install. You may also use the following command from the Package Manager Console.

Command

PM> Install-Package Aspose.Slides.Cpp

How to Create Charts in PPTX Files Using C++

You can create a basic chart with Aspose.Slides for C++ in just a few lines of code.

  1. Instantiate the Presentation class.

  2. Access the first slide.

  3. Add a chart with default data.

  4. Set the index of the chart data sheet.

  5. Get the chart data workbook.

  6. Set the chart title.

  7. Delete default generated series and categories.

  8. Add series and categories.

  9. Take the first chart series and populate its data.

  10. Set the fill color for the series.

  11. Save the PPTX file.

System Requirements

Aspose.Slides for C++ supports all major platforms and operating systems. Please make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with the C++ runtime environment for Windows 32-bit, Windows 64-bit, or Linux 64-bit.
  • Aspose.Slides for C++ DLL referenced in your project.
 

Create PPTX Files Chart - 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(System::Drawing::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 PPTX file.
presentation->Save("column_chart.pptx", SaveFormat::Pptx);
presentation->Dispose();
 
  • About Aspose.Slides for C++ API

    Create PPTX presentation charts online by visiting the

    Live Demos website

    . The live demo has the following benefits

    Online PPTX Chart Creation Live Demos

    Generate PPTX documents charts right now by visiting our Live Demos website . The live demo has the following benefits

      No need to download Aspose API.
      No need to write any code.
      Just upload your PPTX files.
      Charts are created instantly.

    PPTX What is PPTX File Format?

    PPTX files are presentation files created by Microsoft PowerPoint and other presentation apps. Unlike the older binary PPT format, PPTX is based on Office Open XML. A presentation contains slides that can include text, images, formatting, animations, and other media. Slides are shown to an audience as slide shows with custom presentation settings.

    Read More

    Other Supported Charting Formats

    Using C++, you can also create charts in other formats, including:

    PPT (Microsoft PowerPoint 97-2003)