Utwórz wykres 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");
NuGet Download
PM > Install-Package IronXL.Excel
Utwórz wykres Excel

Utwórz wykres Excel

IronXL wspiera tworzenie i edytowanie wykresów dla dokumentów Excel w nowoczesnym formacie pliku XLSX.

Ten przykład pokazuje, jak utworzyć LineChart. Obsługiwane są również inne typy wykresów.

Odkryj nasz Przewodnik po Tworzeniu i Edytowaniu Wykresów Excel w C#
Zobacz na GitHubie

Gotowy, aby rozpocząć?

Nuget Downloads 2,362,812Wersja:2026.11właśnie wydany