如何在 C# 中建立與編輯 Excel 圖表 | IronXL

如何使用 C# 建立 Excel 圖表

This article was translated from English: Does it need improvement?
Translated
View the article in English

using IronXL 在 C# 中建立 Excel 圖表:呼叫 CreateChart() 方法,透過 AddSeries() 新增資料系列,設定標題與圖例,最後使用 Plot() 方法繪製圖表——僅需 5 行程式碼即可完成完整的 Excel 可視化。

快速入門:使用 C# 程式化生成 Excel 圖表

在 IronXL 中建立柱狀圖:使用單一工作表方法建立圖表、新增資料系列、設定標題與圖例、繪製圖表,並儲存。 如需全面了解 IronXL 的功能,請造訪我們的"入門指南"頁面。

  1. using NuGet 套件管理員安裝 https://www.nuget.org/packages/IronXL.Excel

    PM > Install-Package IronXL.Excel
  2. 請複製並執行此程式碼片段。

    IChart chart = worksheet.CreateChart(ChartType.Co/lumn, 5, 5, 20, 10);
    chart.AddSeries("A2:A7", "B2:B7");
    chart.SetTitle("Sales Overview").SetLegendPosition(LegendPosition.Bottom).Plot();
    workbook.SaveAs("SalesChart.xlsx");
  3. 部署至您的生產環境進行測試

    立即透過免費試用,在您的專案中開始使用 IronXL

    arrow pointer

簡化工作流程(6 個步驟)

  1. 安裝 Excel 函式庫以建立 Excel 圖表。
  2. 將現有的 Excel 檔案載入 Workbook 物件中。
  3. 使用 CreateChart 建立一個圖表。
  4. 設定圖表的標題與圖例。
  5. 呼叫 Plot 方法。
  6. Workbook 儲存至 Excel 檔案中。

<div class="learnn-how-section"> <div class="row"> <div class="col-sm-6">

在 .NET 中透過程式碼建立 Excel 圖表

  <ul class="list-unstyled"&gt;
    <li>透過程式碼建立 Excel 圖表</li>
    <li>新增帶有標題和圖例的系列</li>
  </ul>
</div>
 <div class="col-sm-6"&gt;
  <div class="download-card"&gt;
    <img style="box-shadow: none; width: 308px; height: 320px;" src="/img/faq/excel/how-to-work.svg" class="img-responsive learn-how-to-img replaceable-img">
  </div>
</div>