IRONSOFTWAREHOME
创建Excel图表
using IronXL;
using IronXL.Drawing.Charts;

WorkBook workBook = WorkBook.Load("test.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Set the chart type and it's position  on the worksheet.
var chart = workSheet.CreateChart(ChartType.Line, 10, 10, 18, 20);

// Add the series to the chart
// The first parameter represents the address of the range for horizontal(category) axis.
// The second  parameter represents the address of the range for vertical(value) axis.
var series = chart.AddSeries("B3:B8", "A3:A8");

// Set the chart title.
series.Title = "Line Chart";

// Set the legend position.
// Can be removed by setting it to None.
chart.SetLegendPosition(LegendPosition.Bottom);

// We can change the position of the chart.
chart.Position.LeftColumnIndex = 2;
chart.Position.RightColumnIndex = chart.Position.LeftColumnIndex + 3;

// Plot all the data that was added to the chart before.
// Multiple call of this method leads to plotting multiple charts instead of modifying the existing chart.
// Yet there is no possibility to remove chart or edit it's series/position.
// We can just create new one.
chart.Plot();

workBook.SaveAs("CreateLineChart.xlsx");
Imports IronXL
Imports IronXL.Drawing.Charts

Dim workBook As WorkBook = WorkBook.Load("test.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Set the chart type and its position on the worksheet.
Dim chart = workSheet.CreateChart(ChartType.Line, 10, 10, 18, 20)

' Add the series to the chart
' The first parameter represents the address of the range for horizontal(category) axis.
' The second parameter represents the address of the range for vertical(value) axis.
Dim series = chart.AddSeries("B3:B8", "A3:A8")

' Set the chart title.
series.Title = "Line Chart"

' Set the legend position.
' Can be removed by setting it to None.
chart.SetLegendPosition(LegendPosition.Bottom)

' We can change the position of the chart.
chart.Position.LeftColumnIndex = 2
chart.Position.RightColumnIndex = chart.Position.LeftColumnIndex + 3

' Plot all the data that was added to the chart before.
' Multiple calls of this method lead to plotting multiple charts instead of modifying the existing chart.
' Yet there is no possibility to remove chart or edit its series/position.
' We can just create a new one.
chart.Plot()

workBook.SaveAs("CreateLineChart.xlsx")
NuGet Download
PM > Install-Package IronXL.Excel
创建Excel图表

创建Excel图表

IronXL 支持创建和编辑 Excel 文档中采用现代 XLSX 文件格式的图表。

此示例显示如何创建LineChart。 还支持其他图表类型。

浏览我们的 C# Excel 图表创建和编辑指南
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,237,574版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户