PNG JPG BMP TIFF PPTX
Aspose.Slides  for .NET

PPTX 用 C# 格式化圖表

使用用於 .NET API 的服務器端 Aspose.Slides 的原生和高性能 PPTX 文檔圖表,無需使用 Microsoft 或 Adob​​e PDF 等任何軟件。

如何使用 C# 創建 PPTX 圖表

為了創建 PPTX 圖表,我們將使用

Aspose.Slides for .NET

API 是一個功能豐富、功能強大且易於使用的 C# 平台文檔操作 API。打開

NuGet

包管理器,搜索 Aspose.Slides 並安裝。您還可以從包管理器控制台使用以下命令。

命令


PM> Install-Package Aspose.Slides.NET

在 C# 中創建 PPTX 文件圖表的步驟

只需幾行代碼即可使用 Aspose.Slides for .NET API 繪製基本文檔圖表。

  1. 創建 Presentation 類對象。

  2. 選擇幻燈片。

  3. 將圖表添加到幻燈片。

  4. 添加帶有數據的相關圖表系列。

  5. 保存 PPTX 文件

系統要求

所有主要平台和操作系統都支持我們的 API。在執行以下代碼之前,請確保您的系統具有以下先決條件。

  • Microsoft Windows 或兼容 .NET Framework、.NET Core、Windows Azure、Mono 或 Xamarin 平台的操作系統
  • Microsoft Visual Studio 等開發環境
  • 項目中引用的 .NET DLL 的 Aspose.Slides - 使用上面的下載按鈕從 NuGet 安裝
 

創建 PPTX 文件圖表 - C#

//Creating Charts in a Presentation
    Presentation pres = new Presentation();
    
    ISlide slide = pres.Slides[0];
    
    //Creating the default chart
    IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);
    
    //Getting the default chart data worksheet index
    int defaultWorksheetIndex = 0;
    
    //Accessing the chart data worksheet
    IChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
    
    //Delete demo series
    chart.ChartData.Series.Clear();
    
    //Add new series
    chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.Type);
    chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.Type);
    
    //Take first chart series
    IChartSeries series = chart.ChartData.Series[0];
    
    //Add new point (1:3) there.
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 1, 1), fact.GetCell(defaultWorksheetIndex, 2, 2, 3));
    
    //Add new point (2:10)
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 1, 2), fact.GetCell(defaultWorksheetIndex, 3, 2, 10));
    
    //Edit the type of series
    series.Type = ChartType.ScatterWithStraightLinesAndMarkers;
    
    //Changing the chart series marker
    series.Marker.Size = 10;
    series.Marker.Symbol = MarkerStyleType.Star;
    
    //Take second chart series
    series = chart.ChartData.Series[1];
    
    //Add new point (5:2) there.
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 2, 3, 5), fact.GetCell(defaultWorksheetIndex, 2, 4, 2));
    
    //Add new point (3:1)
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 3, 3, 3), fact.GetCell(defaultWorksheetIndex, 3, 4, 1));
    
    //Add new point (2:2)
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 4, 3, 2), fact.GetCell(defaultWorksheetIndex, 4, 4, 2));
    
    //Add new point (5:1)
    series.DataPoints.AddDataPointForScatterSeries(fact.GetCell(defaultWorksheetIndex, 5, 3, 5), fact.GetCell(defaultWorksheetIndex, 5, 4, 1));
    
    //Changing the chart series marker
    series.Marker.Size = 10;
    series.Marker.Symbol = MarkerStyleType.Circle;
    
    pres.Save("AsposeScatterChart.pptx", SaveFormat.Pptx);  

    
 
  • 關於 Aspose.Slides for .NET API

    Aspose.Slides API 可用於讀取、寫入、操作 Microsoft PowerPoint 文檔並將其轉換為 PDF、XPS、HTML、TIFF、ODP 和各種其他格式。可以從頭開始創建新文件並將其保存為相關支持的格式。 Aspose.Slides 是一個獨立的 API,用於創建、解析或操作演示文稿、幻燈片和元素,它不依賴於 Microsoft 或 OpenOffice 等任何軟件。基於圖表模板,從excel數據生成PPT(X)圖表、PPT(X)圖。

    Online PPTX Chart Creation Live Demos

    Generate PPTX documents charts right now by visiting our Live Demos website . The live demo has the following benefits

      No need to download Aspose API.
      No need to write any code.
      Just upload your PPTX files.
      Chart will be created instantly.

    PPTX 什麼是 PPTX 文件格式

    Files with PPTX extension are presentation files created with popular Microsoft PowerPoint application. Unlike the previous version of presentation file format PPT which was binary, the PPTX format is based on the Microsoft PowerPoint open XML presentation file format. A presentation file is a collection of slides where each slide can comprise of text, images, formatting, animations, and other media. These slides are presented to audience in the form of slideshows with custom presentation settings.

    閱讀更多

    其他支持的圖表格式

    使用 C#,可以輕鬆處理不同格式的圖表,包括。

    PPT (微軟PowerPoint 97-2003)