ترشدك هذه المقالة حول كيفية إنشاء مخطط دائري في PowerPoint باستخدام C# REST API. سوف تتعلم كيفية إنشاء مخطط دائري في PowerPoint باستخدام C# RESTful Service باستخدام Cloud SDK المستند إلى .NET. يتم تنفيذ كافة الخطوات في نموذج التعليمات البرمجية مع التعليقات الوصفية.
الشرط الأساسي
تحميل Aspose.Slides Cloud SDK for Dotnet to make a Pie chart
إعداد مشروع C# باستخدام SDK أعلاه للعمل مع الرسوم البيانية الدائرية في شريحة العرض التقديمي
خطوات عمل مخطط دائري في PowerPoint باستخدام واجهة برمجة التطبيقات المستندة إلى C# .NET
- قم بتهيئة عميل API بالمعرف والمفتاح باستخدام فئة SlidesApi
- اقرأ ملف العرض التقديمي المحلي وقم بتحميله على وحدة التخزين السحابية
- قم بإنشاء المخطط الدائري عن طريق تحديد موضعه وحجمه ونوعه لتكوينه
- أضف تسميات إلى المخطط وأنشئ سلسلة من نقاط البيانات للمخطط
- أضف سلسلة إلى المخطط وأضف هذا المخطط إلى الشريحة المستهدفة في العرض التقديمي المحمل باستخدام الطريقة CreateShape()
- قم بتنزيل العرض التقديمي إلى ملف محلي
توضح هذه الخطوات كيفية إنشاء مخطط دائري في PowerPoint باستخدام C# RESTful Service. قم بإنشاء مثيل لكائن المخطط، وقم بتكوين خصائصه، وإضافة فئات، وإنشاء سلسلة نقاط بيانات لإضافتها إلى المخطط الدائري. وأخيرًا، أضف المخطط الدائري إلى الشريحة المستهدفة في العرض التقديمي واحفظه على القرص المحلي.
رمز لإضافة رسم بياني دائري في PowerPoint مع خدمة C# RESTful
using SlidesCloud.SDK; // Importing the SDK for managing presentations | |
using SlidesCloud.SDK.Model; // Importing models used for creating and manipulating presentation components | |
using System; | |
using System.IO; | |
namespace PresentationManager // Custom namespace for this program | |
{ | |
class ShapeAdder | |
{ | |
static void Main(string[] args) // Main entry point of the program | |
{ | |
// Initialize the API client with API key and secret | |
SlidesApi presentationApi = new SlidesApi("Client ID", "Secret"); | |
// Upload the presentation file to the server | |
// Reads the local presentation file and uploads it to the cloud for processing | |
var uploadResult = presentationApi.UploadFile("SampleDeck.pptx", new MemoryStream(File.ReadAllBytes("SampleDeck.pptx"))); | |
// Configure chart properties | |
// Creating a new chart object and defining its position, size, and type | |
Chart customChart = new Chart | |
{ | |
ChartType = Chart.ChartTypeEnum.Pie, // Specifies the type of chart (Pie Chart) | |
X = 150, // X-coordinate of the chart's position on the slide | |
Y = 120, // Y-coordinate of the chart's position on the slide | |
Width = 450, // Width of the chart | |
Height = 350, // Height of the chart | |
Title = new ChartTitle { Text = "Pie Chart" } // Setting the chart title | |
}; | |
// Adding categories (labels) to the chart | |
customChart.Categories = new System.Collections.Generic.List<ChartCategory> | |
{ | |
new ChartCategory { Value = "Category A" }, // First category | |
new ChartCategory { Value = "Category B" }, // Second category | |
new ChartCategory { Value = "Category C" } // Third category | |
}; | |
// Define data series and data points | |
// Creating a series of data points for the chart | |
OneValueSeries chartSeries = new OneValueSeries | |
{ | |
IsColorVaried = true, // Allows different colors for each data point | |
DataPoints = new System.Collections.Generic.List<OneValueChartDataPoint> | |
{ | |
new OneValueChartDataPoint { Value = 35 }, // Data point for Category A | |
new OneValueChartDataPoint { Value = 45 }, // Data point for Category B | |
new OneValueChartDataPoint { Value = 20 } // Data point for Category C | |
} | |
}; | |
// Adding the series to the chart | |
customChart.Series = new System.Collections.Generic.List<Series> { chartSeries }; | |
// Add the chart to the first slide of the presentation | |
Chart insertedChart = (Chart)presentationApi.CreateShape("SampleDeck.pptx", 1, customChart); | |
// Display the number of categories in the chart | |
Console.WriteLine("Number of Categories in the Chart: " + insertedChart.Categories.Count); | |
// Download the updated presentation file from the server | |
Stream updatedPresentationStream = presentationApi.DownloadFile("SampleDeck.pptx"); | |
// Save the downloaded presentation to a local file | |
// Writing the downloaded stream to a new file on disk | |
using (var fileStream = new FileStream("UpdatedDeck.pptx", FileMode.Create, FileAccess.Write)) | |
{ | |
updatedPresentationStream.CopyTo(fileStream); | |
} | |
// Notify the user that the process is complete | |
Console.WriteLine("Updated presentation saved as 'UpdatedDeck.pptx'."); | |
} | |
} | |
} |
يوضح الكود أعلاه كيفية إنشاء مخطط دائري في PPT باستخدام واجهة برمجة التطبيقات المستندة إلى C# .NET. يمكنك التأكد من إضافة عدد من سلاسل جمع البيانات يساوي عدد الفئات المضافة في المخطط. لاحظ أيضًا أن تحميل العرض التقديمي في البداية أمر ضروري وإلا فقد تحصل على استثناءات أثناء تنفيذ التعليمات البرمجية دون تحميل العرض التقديمي المصدر.
علمتنا هذه المقالة إضافة مخطط دائري في العرض التقديمي. لإضافة مخطط شريطي، راجع المقالة الموجودة على إنشاء مخطط شريطي في PowerPoint باستخدام C# REST API.