Creare grafici in presentazioni PPT con C++

Crea grafici in presentazioni PPT con le API lato server di Aspose.Slides for C++ senza Microsoft PowerPoint.

Creare grafici PPT con C++

Usa Aspose.Slides for C++ per creare grafici in presentazioni PPT. Installa il pacchetto da NuGet oppure usa il seguente comando nella Console di Gestione pacchetti.

Comando

PM> Install-Package Aspose.Slides.Cpp

Creare un grafico in 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();

Come creare grafici in file PPT con C++

Crea un grafico in una presentazione PPT con Aspose.Slides for C++ in poche righe di codice.

  1. Crea un oggetto Presentation.
  2. Accedi alla prima diapositiva.
  3. Aggiungi un grafico con dati predefiniti.
  4. Imposta l’indice del foglio dati del grafico.
  5. Ottieni la cartella di lavoro dei dati del grafico.
  6. Imposta il titolo del grafico.
  7. Elimina le serie e le categorie generate per impostazione predefinita.
  8. Aggiungi serie e categorie.
  9. Prendi la prima serie del grafico e inserisci i suoi dati.
  10. Imposta il colore di riempimento della serie.
  11. Mostra il nome della categoria, il nome della serie e il valore nelle etichette dati della seconda serie.
  12. Salva il file PPT.

Requisiti di sistema

Aspose.Slides for C++ supporta le principali piattaforme e i principali sistemi operativi. Assicurati che il tuo ambiente soddisfi i seguenti prerequisiti.

  • Microsoft Windows, Linux, macOS o un altro sistema operativo compatibile con il runtime C++ supportato.
  • La libreria Aspose.Slides for C++ referenziata nel progetto.

Realizzato con Aspose.Slides

Creare grafici PPT online

L’app gratuita Aspose.Slides Chart è realizzata con Aspose.Slides for C++, la stessa API del codice sopra. Aprila e scopri cosa può fare l’API con i tuoi file PPT.

  • Funziona nel browser, senza installare nulla.
  • Scopri come Aspose.Slides crea i grafici prima di scrivere codice.
  • Crea un grafico da dati Excel o da una tabella.
  • Scaricalo come file PPT o come immagine.

Cos'è il formato file PPT

Un file PPT contiene una raccolta di diapositive per una presentazione. Usa il formato di file binario di Microsoft PowerPoint 97-2003. Un file PPT può contenere testo, elenchi puntati, immagini, contenuti multimediali e altri oggetti OLE incorporati. Microsoft ha introdotto il più recente formato PPTX con PowerPoint 2007. PPTX si basa su Office Open XML ed è diverso dal vecchio formato binario. Anche altre applicazioni, come OpenOffice Impress e Apple Keynote, possono creare file PPT.

Leggi di più

Altri formati supportati per i grafici

Con C++, puoi creare grafici anche in altri formati.