Այս հոդվածը ձեզ ուղղորդում է, թե ինչպես ստեղծել կարկանդակ գծապատկեր PowerPoint-ում C# REST API-ով: Դուք կսովորեք ինչպես ստեղծել կարկանդակ աղյուսակ PowerPoint-ում C# RESTful ծառայության միջոցով՝ օգտագործելով .NET-ի վրա հիմնված Cloud SDK-ն: Բոլոր քայլերը կատարվում են օրինակելի կոդում՝ նկարագրական մեկնաբանությունների հետ միասին:
Նախապայման
[Ստեղծել հաշվի API հավատարմագրեր] ( https://kb.aspose.cloud/ hy/total/net/how-to-create-aspose-cloud-apis-account/)
Բեռնել Aspose.Slides Cloud SDK for Dotnet to make a Pie chart
Կարգավորեք C# նախագիծը վերը նշված SDK-ով` ներկայացման սլայդում Pie գրաֆիկների հետ աշխատելու համար
PowerPoint-ում կարկանդակ գծապատկեր ստեղծելու քայլեր C# .NET-ի վրա հիմնված API-ով
- Նախաձեռնեք API հաճախորդը ID-ով և KEY-ով, օգտագործելով SlidesApi դասը
- Կարդացեք տեղական ներկայացման ֆայլը և վերբեռնեք այն Cloud պահեստում
- Ստեղծեք Pie աղյուսակը՝ սահմանելով դրա դիրքը, չափը և տեսակը՝ այն կարգավորելու համար
- Ավելացրեք պիտակներ գծապատկերում և ստեղծեք մի շարք տվյալների կետեր գծապատկերի համար
- Ավելացրեք շարքեր գծապատկերում և ավելացրեք այս գծապատկերը թիրախային սլայդում բեռնված ներկայացման մեջ CreateShape() մեթոդով:
- Ներբեռնեք ներկայացումը տեղական ֆայլում
Այս քայլերը նկարագրում են ինչպես եք պատրաստում կարկանդակ գծապատկեր PowerPoint-ում C# RESTful ծառայության միջոցով: Ստեղծեք գծապատկերի օբյեկտը, կազմաձևեք դրա հատկությունները, ավելացրեք կատեգորիաներ և ստեղծեք տվյալների կետերի շարքեր՝ Pie աղյուսակում ավելացնելու համար: Վերջապես, ներկայացման նպատակային սլայդին ավելացրեք Pie աղյուսակը և պահեք տեղական սկավառակի վրա:
Կոդ՝ 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'."); | |
} | |
} | |
} |
Վերոնշյալ կոդը ցույց է տալիս ինչպես ստեղծել Pie աղյուսակը PPT-ում C# .NET-ի վրա հիմնված API-ով: Դուք կարող եք ապահովել, որ ավելացնեք տվյալների հավաքագրման այնքան շարք, որքան գծապատկերում ավելացված կատեգորիաների քանակը: Նաև նկատի ունեցեք, որ սկզբում ներկայացման բեռնումը պարտադիր է, այլապես կարող եք բացառություններ ստանալ՝ առանց սկզբնաղբյուր ներկայացման վերբեռնման կոդը կատարելիս:
Այս հոդվածը մեզ սովորեցրել է ներկայացնել Կարկանդակ աղյուսակը ներկայացման մեջ: Գծաձև գծապատկեր ավելացնելու համար տես Ստեղծեք գծային գծապատկեր PowerPoint-ում C# REST API-ով-ի հոդվածը: