C# REST API를 사용하여 PowerPoint에서 막대 차트 만들기

이 문서에서는 C# REST API를 사용하여 PowerPoint에서 막대 차트를 생성하는 방법을 안내합니다. .NET 기반 Cloud SDK를 사용하여 C# RESTful 서비스로 PowerPoint에서 막대 그래프를 만드는 방법을 알아봅니다. 여기에는 차트 추가 및 데이터 설정에 대한 완전한 정보가 포함되어 있습니다.

전제조건

C# .NET 기반 API를 사용하여 PowerPoint에 세로 막대형 차트를 추가하는 단계

  1. 차트 추가를 위해 클라이언트 ID와 비밀번호로 SlidesApi를 초기화합니다.
  2. 프레젠테이션 파일을 클라우드에 업로드
  3. Chart 클래스를 사용하여 새 차트 구성 개체를 만들고 차트 유형을 설정합니다.
  4. 차트 제목 추가 및 차트 카테고리 초기화
  5. 차트의 데이터 시리즈를 초기화하고 데이터 시리즈를 생성한 후 첫 번째 데이터 시리즈를 추가합니다.
  6. 필요한 경우 차트에 대한 추가 데이터 시리즈를 초기화하세요.
  7. CreateShape() 메소드를 사용하여 프레젠테이션의 첫 번째 슬라이드에 차트를 추가하고 필요한 경우 다운로드하세요.

이 단계에서는 C# .NET 기반 API를 사용하여 PowerPoint에서 막대 차트를 만드는 방법을 설명합니다. SlidesApi 개체를 만들고, 프레젠테이션을 업로드하고, Chart 개체를 만들고, 차트 유형, 위치, 크기, 제목, 범주 및 원하는 데이터 시리즈를 설정합니다. 차트에 데이터 시리즈를 추가하고 첫 번째 슬라이드에 차트를 추가합니다.

C# REST 인터페이스를 사용하여 PowerPoint에서 막대 그래프를 만드는 코드

using Aspose.Slides.Cloud.Sdk;
using Aspose.Slides.Cloud.Sdk.Model;
using System;
using System.IO;
namespace AsposeTestCodes
{
class Program
{
static void Main(string[] args) // For adding a custom shape to a presentation
{
// Initialize the Slides API using client ID and secret key
SlidesApi slidesApi = new SlidesApi("Client ID", "Secret");
// Upload the presentation file to the cloud
var uploadResponse = slidesApi.UploadFile("MyPresentation.pptx", new MemoryStream(File.ReadAllBytes("MyPresentation.pptx")));
// Create a new chart configuration object
Chart chartConfig = new Chart();
// Define chart type as a stacked bar chart
chartConfig.ChartType = Chart.ChartTypeEnum.StackedBar;
// Set the position and dimensions of the chart on the slide
chartConfig.X = 150; // Horizontal position (pixels)
chartConfig.Y = 150; // Vertical position (pixels)
chartConfig.Width = 500; // Chart width (pixels)
chartConfig.Height = 350; // Chart height (pixels)
// Add a title to the chart
chartConfig.Title = new ChartTitle { Text = "Bar Chart Example" };
// Initialize categories (x-axis labels) for the chart
chartConfig.Categories = new System.Collections.Generic.List<ChartCategory>();
chartConfig.Categories.Add(new ChartCategory { Value = "Group A" }); // First category
chartConfig.Categories.Add(new ChartCategory { Value = "Group B" }); // Second category
chartConfig.Categories.Add(new ChartCategory { Value = "Group C" }); // Third category
chartConfig.Categories.Add(new ChartCategory { Value = "Group D" }); // Fourth category
// Initialize data series for the chart
chartConfig.Series = new System.Collections.Generic.List<Series>();
// Create the first data series
OneValueSeries firstSeries = new OneValueSeries();
firstSeries.DataPoints = new System.Collections.Generic.List<OneValueChartDataPoint>();
firstSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 15 }); // Value for Group A
firstSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 40 }); // Value for Group B
firstSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 25 }); // Value for Group C
firstSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 10 }); // Value for Group D
// Add the first data series to the chart
chartConfig.Series.Add(firstSeries);
// Create the second data series
OneValueSeries secondSeries = new OneValueSeries();
secondSeries.DataPoints = new System.Collections.Generic.List<OneValueChartDataPoint>();
secondSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 35 }); // Value for Group A
secondSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 20 }); // Value for Group B
secondSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 45 }); // Value for Group C
secondSeries.DataPoints.Add(new OneValueChartDataPoint { Value = 15 }); // Value for Group D
// Add the second data series to the chart
chartConfig.Series.Add(secondSeries);
// Add the chart to the first slide of the presentation
Chart createdChart = (Chart)slidesApi.CreateShape("MyPresentation.pptx", 1, chartConfig);
// Print the number of categories in the chart to the console
Console.WriteLine(createdChart.Categories.Count);
// Download the modified presentation from the cloud
Stream stream = slidesApi.DownloadFile("MyPresentation.pptx");
// Save the downloaded file to the local system
var fs = new FileStream("Downloaded.pptx", FileMode.Create, FileAccess.Write);
stream.CopyTo(fs); // Copy the stream data to the local file
}
}
}

이 코드는 C# Low Code API를 사용하여 PowerPoint에서 막대 그래프를 만드는 방법 프로세스를 보여줍니다. ShowDataLabelsOverMaximum, BackWall, SideWall, Floor 및 Legend 등을 포함한 Chart 개체의 ChartTypeEnum 및 기타 매개 변수를 사용하여 ClusteredColumn, Column3D, ClusteredCone 및 Line 등과 같은 다양한 차트 유형을 설정할 수 있습니다.

이 기사에서는 PowerPoint에서 막대 차트를 만드는 방법을 배웠습니다. HTML을 PowerPoint로 변환하려면 NET REST API를 사용하여 HTML을 PowerPoint로 변환의 기사를 참조하세요.

 한국인