این مقاله نحوه ایجاد نمودار میله ای در PowerPoint با C# REST API را راهنمایی می کند. یاد خواهید گرفت چگونه با C# RESTful Service یک نمودار میله ای در پاورپوینت ایجاد کنید با استفاده از یک Cloud SDK مبتنی بر NET. این شامل اطلاعات کامل در مورد افزودن نمودار و تنظیم داده است.
پیش نیاز
دانلود کنید Aspose.Slides Cloud SDK for Dotnet to add a chart
پروژه سی شارپ را با SDK بالا برای کار با نمودارها در یک ارائه راه اندازی کنید
مراحل افزودن نمودار ستونی در پاورپوینت با C#.NET-based API
- SlidesApi را با شناسه مشتری و راز برای افزودن نمودار راه اندازی کنید
- فایل ارائه را در Cloud آپلود کنید
- یک شیء پیکربندی نمودار جدید با استفاده از کلاس Chart ایجاد کنید و نوع نمودار را تنظیم کنید
- عنوان نمودار را اضافه کنید و دسته ها را برای نمودار مقداردهی کنید
- سری داده ها را برای نمودار راه اندازی کنید، سری داده ها را ایجاد کنید و اولین سری داده ها را اضافه کنید
- در صورت لزوم، سری داده های بیشتری را برای نمودار مقداردهی کنید
- نمودار را با استفاده از روش CreateShape() به اسلاید اول ارائه اضافه کنید و در صورت نیاز آن را دانلود کنید.
این مراحل نحوه ایجاد نمودار میله ای در پاورپوینت با C#.NET-based API را شرح می دهد. شی SlidesApi را ایجاد کنید، ارائه را آپلود کنید، یک شی نمودار ایجاد کنید، نوع نمودار، موقعیت، ابعاد، عنوان، دسته ها و سری داده های دلخواه را تنظیم کنید. سری داده ها را به نمودار اضافه کنید و نمودار را به اسلاید اول اضافه کنید.
کد ایجاد نمودار نواری در پاورپوینت با رابط C# REST
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 را نشان می دهد. با استفاده از ChartTypeEnum و سایر پارامترها در شی نمودار از جمله ShowDataLabelsOverMaximum، BackWall، SideWall، Floor و Legend و غیره میتوانید انواع نمودارهای مختلفی مانند ClusteredColumn، Column3D، ClusteredCone، و Line و غیره را تنظیم کنید.
این مقاله ایجاد نمودار میله ای در پاورپوینت را به ما آموزش داده است. برای تبدیل HTML به پاورپوینت به مقاله با NET REST API HTML را به پاورپوینت تبدیل کنید مراجعه کنید.