ترشدك هذه المقالة حول كيفية إنشاء مخطط شريطي في PowerPoint باستخدام C# REST API. سوف تتعلم كيفية إنشاء رسم بياني شريطي في PowerPoint باستخدام C# RESTful Service باستخدام Cloud SDK المستند إلى .NET. أنه يحتوي على معلومات كاملة حول إضافة الرسم البياني وإعداد البيانات.
الشرط الأساسي
تحميل Aspose.Slides Cloud SDK for Dotnet to add a chart
إعداد مشروع C# باستخدام SDK أعلاه للعمل مع الرسوم البيانية في العرض التقديمي
خطوات إضافة مخطط عمودي في PowerPoint باستخدام واجهة برمجة التطبيقات المستندة إلى C# .NET
- قم بتهيئة SlidesApi بمعرف العميل وسر إضافة مخطط
- قم بتحميل ملف العرض التقديمي إلى السحابة
- قم بإنشاء كائن تكوين مخطط جديد باستخدام فئة المخطط وقم بتعيين نوع المخطط
- أضف عنوان المخطط وقم بتهيئة الفئات للمخطط
- قم بتهيئة سلسلة البيانات للمخطط، وقم بإنشاء سلسلة البيانات، وأضف سلسلة البيانات الأولى
- قم بتهيئة المزيد من سلاسل البيانات للمخطط إذا لزم الأمر
- أضف المخطط إلى الشريحة الأولى من العرض التقديمي باستخدام طريقة CreateShape() وقم بتنزيله إذا لزم الأمر
تصف هذه الخطوات كيفية إنشاء مخطط شريطي في PowerPoint باستخدام واجهة برمجة التطبيقات المستندة إلى C# .NET. قم بإنشاء كائن SlidesApi، وتحميل العرض التقديمي، وإنشاء كائن مخطط، وتعيين نوع المخطط والموضع والأبعاد والعنوان والفئات وسلسلة البيانات المطلوبة. أضف سلسلة البيانات إلى المخطط وأضف المخطط إلى الشريحة الأولى.
رمز لإنشاء رسم بياني شريطي في PowerPoint باستخدام واجهة 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 | |
} | |
} | |
} |
يوضح هذا الرمز عملية كيفية عمل رسم بياني شريطي في PowerPoint باستخدام C# Low Code API. يمكنك تعيين نوع مخطط مختلف مثل ClusteredColumn وColumn3D وClusteredCone وLine وما إلى ذلك، باستخدام ChartTypeEnum والمعلمات الأخرى في كائن Chart بما في ذلك ShowDataLabelsOverMaximum وBackWall وSideWall وFlor وLegend وما إلى ذلك.
لقد علمتنا هذه المقالة إنشاء مخطط شريطي في برنامج PowerPoint. لتحويل HTML إلى PowerPoint، راجع المقالة الموجودة على تحويل HTML إلى PowerPoint باستخدام NET REST API.