Criar gráficos em apresentações PPTX com C++
Crie gráficos em apresentações PPTX usando as APIs de servidor do Aspose.Slides for C++ sem o Microsoft PowerPoint.
Criar gráficos PPTX com C++
Use o Aspose.Slides for C++ para criar gráficos em apresentações PPTX. Instale o pacote pelo NuGet ou use o seguinte comando no Console do Gerenciador de Pacotes.
Comando
PM> Install-Package Aspose.Slides.CppCriar um gráfico em PPTX – 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 PPTX file.
presentation->Save(u"column_chart.pptx", SaveFormat::Pptx);
presentation->Dispose();Como criar gráficos em arquivos PPTX com C++
Crie um gráfico em uma apresentação PPTX com o Aspose.Slides for C++ em poucas linhas de código.
- Crie um objeto
Presentation. - Acesse o primeiro slide.
- Adicione um gráfico com dados padrão.
- Defina o índice da planilha de dados do gráfico.
- Obtenha a pasta de trabalho de dados do gráfico.
- Defina o título do gráfico.
- Exclua as séries e categorias geradas por padrão.
- Adicione séries e categorias.
- Pegue a primeira série do gráfico e preencha seus dados.
- Defina a cor de preenchimento da série.
- Mostre o nome da categoria, o nome da série e o valor nos rótulos de dados da segunda série.
- Salve o arquivo PPTX.
Requisitos do sistema
O Aspose.Slides for C++ oferece suporte às principais plataformas e sistemas operacionais. Verifique se o seu ambiente atende aos seguintes pré-requisitos.
- Microsoft Windows, Linux, macOS ou outro sistema operacional compatível com o runtime C++ suportado.
- A biblioteca Aspose.Slides for C++ referenciada no seu projeto.
Criado com Aspose.Slides
Criar gráficos PPTX online
O aplicativo gratuito Aspose.Slides Chart é criado com Aspose.Slides for C++, a mesma API do código acima. Abra-o e veja o que a API pode fazer com seus próprios arquivos PPTX.
- Funciona no seu navegador, sem instalar nada.
- Veja como o Aspose.Slides cria gráficos antes de escrever código.
- Crie um gráfico a partir de dados do Excel ou de uma tabela.
- Baixe-o como arquivo PPTX ou como imagem.
O que é PPTX Formato de Arquivo
Arquivos PPTX são arquivos de apresentação criados pelo Microsoft PowerPoint e por outros aplicativos de apresentação. Ao contrário do antigo formato binário PPT, o PPTX é baseado em Office Open XML. Uma apresentação contém slides que podem incluir texto, imagens, formatação, animações e outras mídias. Os slides são exibidos ao público como apresentações de slides com configurações personalizadas.
Outros formatos compatíveis para gráficos
Com C++, você também pode criar gráficos em outros formatos.