IronXL 操作指南 創建和編輯圖表 How to Create and Edit Excel Charts in C Curtis Chau 更新:2026年1月20日 下載 IronXL NuGet 下載 DLL 下載 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronXL使 C# 開發人員能夠透過簡單的 API 呼叫以程式設計方式建立、編輯和刪除 Excel 圖表。 您可以直接從資料產生長條圖、折線圖、圓餅圖和其他圖表類型,而無需依賴 Excel Interop。 在 Excel 中,圖表是資料的圖形化表示,用於直觀地顯示和分析資訊。 Excel 提供各種圖表類型,例如長條圖、折線圖和圓餅圖,每種圖表都適用於不同的資料和分析需求。 When working with IronXL's comprehensive Excel library, you can programmatically create these visualizations to enhance your reports and dashboards. 快速入門:在幾秒鐘內創建並繪製折線圖 使用IronXL,您只需幾行程式碼即可完成安裝、載入工作簿、呼叫 CreateChart、新增資料系列、設定標題和圖例位置以及 Plot。 本範例展示如何使用原生 C# 方法建立圖表,而無需 Interop 開銷。 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronXl.Excel PM > Install-Package IronXl.Excel 複製並運行這段程式碼。 // Load workbook and create a line chart with data series var chart = workSheet.CreateChart(ChartType.Line, 2, 2, 15, 10).AddSeries("A2:A10","B2:B10").Title = workSheet["B1"].StringValue; // Set title and legend position, then plot the chart chart.SetTitle("Quick Line Chart").SetLegendPosition(LegendPosition.Bottom).Plot(); 部署到您的生產環境進行測試 今天就在您的專案中開始使用免費試用IronXL Free 30 Day Trial 最簡工作流程(5個步驟) 下載用於建立和編輯圖表的 C# 庫。 準備用於建立圖表的數據 使用`CreateChart`方法設定圖表類型和位置 使用`AddSeries`方法新增資料系列 使用`Plot`方法繪製圖表 開始使用IronXL 如何在Excel中建立圖表? IronXL支援長條圖、散佈圖、折線圖、圓餅圖、長條圖和麵積圖。 若要建立圖表,請指定下列組件。 This flexibility allows you to create Excel spreadsheets with rich visualizations tailored to your data presentation needs. 使用 CreateChart 指定圖表類型和工作表位置。 新增序列 AddSeries。 此方法對某些圖表類型僅接受單列資料。第一個參數是水平軸值。 第二點是縱軸數值。 (可選)指定係列名稱、圖表名稱和圖例位置。 呼叫 Plot 來渲染圖表。 多次呼叫會產生多個圖表。 Let's create charts from the data in the chart.xlsx Excel file. A preview of the data is displayed below: 創建長條圖的流程是什麼? 長條圖非常適合比較不同類別之間的數值。 When you load spreadsheet data, you can visualize it effectively using column charts to highlight differences between data points. 以下範例示範如何使用動物族群資料建立多系列長條圖: :path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-column-chart.cs using IronXL; using IronXL.Drawing.Charts; WorkBook workBook = WorkBook.Load("chart.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; // Set the chart type and position IChart chart = workSheet.CreateChart(ChartType.Column, 5, 5, 20, 10); string xAxis = "A2:A7"; // Add the series IChartSeries series = chart.AddSeries(xAxis, "B2:B7"); series.Title = workSheet["B1"].StringValue; // Add the series series = chart.AddSeries(xAxis, "C2:C7"); series.Title = workSheet["C1"].StringValue; // Add the series series = chart.AddSeries(xAxis, "D2:D7"); series.Title = workSheet["D1"].StringValue; // Set the chart title chart.SetTitle("Column Chart"); // Set the legend position chart.SetLegendPosition(LegendPosition.Bottom); // Plot the chart chart.Plot(); workBook.SaveAs("columnChart.xlsx"); $vbLabelText $csharpLabel 如何建立折線圖? 折線圖非常擅長展示隨時間變化的趨勢。由於折線圖和長條圖顯示的資訊相同,因此在兩者之間切換只需更改圖表類型即可。 這使得折線圖在讀取包含時間序列資料的 XLSX 檔案時特別有用: :path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-pie-chart.cs using IronXL; using IronXL.Drawing.Charts; WorkBook workBook = WorkBook.Load("chart.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; // Set the chart type and position IChart chart = workSheet.CreateChart(ChartType.Pie, 5, 5, 20, 10); string xAxis = "A2:A7"; // Add the series IChartSeries series = chart.AddSeries(xAxis, "B2:B7"); series.Title = workSheet["B1"].StringValue; // Set the chart title chart.SetTitle("Pie Chart"); // Set the legend position chart.SetLegendPosition(LegendPosition.Bottom); // Plot the chart chart.Plot(); workBook.SaveAs("pieChart.xlsx"); $vbLabelText $csharpLabel 何時該使用圓餅圖? 圓餅圖顯示整體的比例和百分比。 餅圖只需要一列數據,因此更容易實現。 They're effective when you want to convert spreadsheet data into visual representations of market share, budget allocation, or category distribution: :path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-pie-chart.cs using IronXL; using IronXL.Drawing.Charts; WorkBook workBook = WorkBook.Load("chart.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; // Set the chart type and position IChart chart = workSheet.CreateChart(ChartType.Pie, 5, 5, 20, 10); string xAxis = "A2:A7"; // Add the series IChartSeries series = chart.AddSeries(xAxis, "B2:B7"); series.Title = workSheet["B1"].StringValue; // Set the chart title chart.SetTitle("Pie Chart"); // Set the legend position chart.SetLegendPosition(LegendPosition.Bottom); // Plot the chart chart.Plot(); workBook.SaveAs("pieChart.xlsx"); $vbLabelText $csharpLabel 如何編輯現有圖表? 在使用現有的 Excel 檔案時,您可能需要修改已建立的圖表。 IronXL提供了編輯現有圖表的簡單方法,讓您更新標題、重新定位圖例和刷新資料。 This is useful when editing Excel files that contain pre-existing visualizations. 您可以編輯現有圖表中的圖例位置和圖表標題。 要編輯圖表,首先需要存取"圖表"屬性並選擇目標圖表來檢索該圖表。 然後存取圖表屬性進行編輯: :path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-edit-chart.cs using IronXL; using IronXL.Drawing.Charts; WorkBook workBook = WorkBook.Load("pieChart.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; // Retrieve the chart IChart chart = workSheet.Charts[0]; // Edit the legend position chart.SetLegendPosition(LegendPosition.Top); // Edit the chart title chart.SetTitle("Edited Chart"); workBook.SaveAs("editedChart.xlsx"); $vbLabelText $csharpLabel 前 後 如何從Excel中刪除圖表? 有時需要清理 Excel 文件,刪除過時或不必要的圖表。 This is common when managing worksheets containing multiple visualizations. 若要從電子表格中刪除現有圖表,請先從"圖表"屬性中擷取該圖表。 您將收到一份圖表清單。 將目標圖表物件傳遞給 RemoveChart: :path=/static-assets/excel/content-code-examples/how-to/create-edit-charts-remove-chart.cs using IronXL; using IronXL.Drawing.Charts; using System.Collections.Generic; WorkBook workBook = WorkBook.Load("pieChart.xlsx"); WorkSheet workSheet = workBook.DefaultWorkSheet; // Retrieve the chart List<IChart> chart = workSheet.Charts; // Remove the chart workSheet.RemoveChart(chart[0]); workBook.SaveAs("removedChart.xlsx"); $vbLabelText $csharpLabel 進階圖表自訂 除了基本的圖表建立功能外, IronXL還支援進階自訂選項。 When creating complex reports or dashboards, you can combine charts with other Excel features like conditional formatting to create comprehensive data visualizations. 對於商業應用而言,圖表通常需要根據資料庫查詢或即時資料來源動態產生。 IronXL與.NET資料結構無縫集成,可讓您從 Lists 或任何可枚舉集合建立圖表。 這使其成為產生包含視覺元素的自動化報告的理想選擇。 概括 IronXL為在 C# 應用程式中處理 Excel 圖表提供了一套完整的解決方案。 無論是建立新的視覺化圖表、修改現有圖表,或是刪除過時的圖表,該程式庫都提供了無需 Excel Interop 的直覺方法。透過將圖表功能與 IronXL 的其他功能(例如資料操作和格式化)結合,您可以建立複雜的 Excel 自動化解決方案,從而增強.NET應用程式中的資料呈現和分析能力。 常見問題解答 如何在不使用 Interop 的情況下,以 C# 程式化的方式建立 Excel 圖表? IronXl.Excel 提供了一個簡單的 API,可以在 C# 中建立 Excel 圖表,而不需要 Interop 依賴。您可以使用 CreateChart 方法來指定圖表類型和位置,使用 AddSeries 來新增資料,以及使用 Plot 來渲染圖表 - 所有這些都可以透過 C# 原始程式碼來完成。 使用 C# 可以在 Excel 試算表中建立哪些類型的圖表? IronXL 支援建立各種圖表類型,包括柱狀圖、散點圖、線圖、圓餅圖、條狀圖和面積圖。您可以在呼叫 CreateChart 方法時指定圖表類型,並使用標題、圖例和資料系列自訂每個圖表。 如何以程式化方式在 Excel 圖表中加入資料序列? 使用 IronXL 的 AddSeries 方法將資料新增至您的圖表。此方法接受儲存格範圍作為參數 - 第一個參數為水平軸值,第二個參數為垂直軸值。您可以添加多個序列來創建多序列圖表。 使用 C# 在 Excel 中建立折線圖的最快方法是什麼? 使用 IronXL,您只需幾行代碼即可創建線形圖:使用 CreateChart(ChartType.Line) 初始化圖表,AddSeries() 添加您的資料範圍,SetTitle() 設定圖表標題,Plot() 在工作表上渲染圖表。 我可以自訂標題和圖例位置等圖表屬性嗎? 是的,IronXl.Excel 允許完全自訂 Excel 圖表。您可以使用 SetTitle() 添加圖表標題,使用 SetLegendPosition() 放置圖例(頂部、底部、左側、右側),還可以選擇性地指定系列名稱,以便更好地識別數據。 我需要安裝 Microsoft Excel 才能以程式化方式建立圖表嗎? 不,IronXL 可獨立工作,無需安裝 Microsoft Excel。它在內部處理所有 Excel 檔案作業和圖表建立,因此非常適合伺服器環境和無法安裝 Excel 的應用程式。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 12 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Howto.php Line: 31 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/ready_to_started_202509.php Line: 19 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/libraries/Render.php Line: 489 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Howto.php Line: 31 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 準備好開始了嗎? Nuget 下載 1,890,100 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:1,890,100 查看許可證 Docs 在這頁 開始使用入門概述在C#中使用Excel文件而不使用Interop使用授權金鑰安裝 IronXL 庫在 macOS 上使用在 Linux 上使用部署到雲端/容器部署到 Azure部署到 AWS在Docker中設置.NET 語言支持.NET MAUI上使用Excel在Blazor中讀取Excel文件在VB.NET中使用Excel文件教程如何在C#中讀取Excel文件在 C# 中創建 Excel 文件使用C#打開和寫入Excel文件操作指南工作簿創建電子表格載入試算表在C#中導出到Excel在 C# 中讀取 XLSX 文件在C#中讀取CSV在ASP.NET Web應用程序中讀取Excel文件在.NET中寫入CSV在C#中打開Excel工作表將數據表轉換為CSV將XLSX轉換為CSV、JSON、XML轉換電子表格文件類型導入及導出為 DataSet編輯工作簿元數據用密碼加密工作簿管理工作表工作表編輯公式選擇範圍命名範圍命名表創建和編輯圖表凍結窗格添加行和列自動調整列和欄用密碼加密工作表分組和取消分組新增、提取和移除圖片在C#中創建Excel圖表單元格範圍在.NET中寫入Excel值在C#中導入Excel數據排序單元格範圍修剪儲存格範圍清除儲存格複製單元格設置超鏈接合併和拆分單元格單元格字體和大小單元格邊框和對齊背景圖案與顏色條件格式數學函數添加評論設置單元格數據格式在C#中編輯Excel文件故障排除故障排除指南在IronXL中套用授權密鑰文件大小限制Excel限制:字符串列表的數據驗證常见問题IronXL - 安全CVE異常訊息在 Web.config 中設置許可密钥產品更新變更日志里程碑里程碑:性能里程碑:增強視頻教程API 參考 在這頁 開始使用IronXL如何在Excel中建立圖表?如何編輯現有圖表?如何從Excel中刪除圖表?進階圖表自訂概括 A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 17 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php Line: 71 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/views/products/how-to/index.php Line: 2 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Howto.php Line: 31 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once A PHP Error was encountered Severity: Notice Message: Undefined index: IronXl.Excel Filename: helpers/counter_helper.php Line Number: 85 Backtrace: File: /var/www/ironpdf.com/application/helpers/counter_helper.php Line: 85 Function: _error_handler File: /var/www/ironpdf.com/application/views/main/sections/still_scrolling_202512.php Line: 24 Function: getTotalDonwloadNumber File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php Line: 71 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/views/products/how-to/index.php Line: 2 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 88 Function: view File: /var/www/ironpdf.com/application/libraries/Render.php Line: 552 Function: view File: /var/www/ironpdf.com/application/controllers/Products/Howto.php Line: 31 Function: render_products_view File: /var/www/ironpdf.com/index.php Line: 292 Function: require_once 還在捲動嗎? 想要快速證明? PM > Install-Package IronXl.Excel 執行範例 觀看您的資料變成試算表。 免費 NuGet 下載 總下載量:1,890,100 查看許可證