C#에서 Excel 차트를 만들고 편집하는 방법

How to Create and Edit Excel Charts in C#

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 오버헤드 없이 차트를 생성하는 방법을 보여줍니다.

  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronXl.Excel 설치하기

    PM > Install-Package IronXl.Excel
  2. 다음 코드 조각을 복사하여 실행하세요.

    // 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();
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronXL 사용 시작하기

    arrow pointer


IronXL로 시작해 보세요


Excel에서 차트를 어떻게 만드나요?

IronXL은 컬럼, 스캐터, 라인, 파이, 바, 영역 차트를 지원합니다. 차트를 만들려면 다음 구성 요소를 지정하세요. This flexibility allows you to create Excel spreadsheets with rich visualizations tailored to your data presentation needs.

  1. CreateChart를 사용하여 차트 유형과 워크시트 위치를 지정합니다.
  2. AddSeries로 시리즈를 추가합니다. 이 메소드는 일부 차트 유형에 대해 단일 열을 허용합니다. 첫 번째 매개변수는 수평축 값입니다. 두 번째는 세로 축 값입니다.
  3. 옵션으로 시리즈 이름, 차트 이름 및 범례 위치를 지정합니다.
  4. 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
기린, 코끼리, 코뿔소의 월별 개체 수를 보여주는 동물 데이터 표 및 해당 그룹화된 범례 차트를 포함한 Excel 스프레드시트

선을 어떻게 만듭니까?

선 차트는 시간 경과에 따른 추세를 보여주기에 탁월합니다. 선 차트는 범례 차트와 동일한 정보를 표시하므로, 차트 유형을 변경하는 것만으로 전환이 가능합니다. 이는 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
기린, 코끼리, 코뿔소에 대해 세 가지 추세선을 포함한 선 차트와 해당하는 동물 데이터 표를 보여주는 Excel 스프레드시트

파이 차트는 언제 사용해야 합니까?

파이 차트는 전체의 비율과 백분율을 보여줍니다. 파이 차트의 경우 데이터 한 열만 필요하므로 구현이 간단합니다. 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
기린의 월별 분포를 보여주는 야생 동물 데이터 스프레드시트 및 4월에 89마리 (21%)를 강조 표시한 파이 차트

기존 차트를 어떻게 편집합니까?

기존 Excel 파일을 작업할 때 이미 생성된 차트를 수정해야 할 수도 있습니다. IronXL은 기존 차트를 편집할 수 있는 간단한 방법을 제공하여 제목을 업데이트하고 범례를 재배치하고 데이터를 새로 고칠 수 있습니다. This is useful when editing Excel files that contain pre-existing visualizations.

기존 차트의 범례 위치와 차트 제목을 편집할 수 있습니다. 차트를 편집하려면 먼저 Charts 속성에 액세스하여 대상 차트를 선택하여 가져옵니다. 그런 다음 차트 속성에 접근하여 수정합니다:

: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
Pie chart showing monthly data from Jan-Jun with color-coded segments and legend below
Pie chart showing monthly data distribution from January to June with color-coded segments and legend

Excel에서 차트를 어떻게 제거합니까?

때로는 오래되거나 불필요한 차트를 제거하여 Excel 파일을 정리해야 합니다. This is common when managing worksheets containing multiple visualizations. 스프레드시트에서 기존 차트를 제거하려면 먼저 Charts 속성에서 차트를 가져옵니다. 차트 목록을 받게 됩니다. 대상 차트 객체를 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 데이터 구조와 원활하게 통합되어 DataTables, Lists 또는 모든 열거 가능한 컬렉션에서 차트를 만들 수 있습니다. 이는 시각적 요소를 포함하는 자동화된 보고서를 생성하는 데 이상적입니다.

요약

IronXL은 C# 애플리케이션에서 Excel 차트를 작업할 수 있는 완전한 솔루션을 제공합니다. 새로운 시각화를 생성하든, 기존 시각화를 수정하든, 오래된 차트를 제거하든, Excel 인터롭을 필요로 하지 않는 직관적인 방법을 제공합니다. 차트 기능을 데이터 조작 및 서식과 같은 IronXL의 다른 기능과 결합하여, NET 애플리케이션에서 데이터 표현 및 분석을 개선하는 복잡한 Excel 자동화 솔루션을 구축할 수 있습니다.

자주 묻는 질문

Interop을 사용하지 않고 C#에서 Excel 차트를 프로그래밍 방식으로 생성하는 방법은 무엇인가요?

IronXL은 상호 운용성 종속성 없이 C#에서 Excel 차트를 생성할 수 있는 간단한 API를 제공합니다. CreateChart 메서드를 사용하여 차트 유형과 위치를 지정하고, AddSeries를 사용하여 데이터를 추가하고, Plot을 사용하여 차트를 렌더링할 수 있습니다. 이 모든 작업은 네이티브 C# 코드로 수행됩니다.

C#을 사용하여 Excel 스프레드시트에 어떤 유형의 차트를 만들 수 있나요?

IronXL은 막대형 차트, 산점도형 차트, 선형 차트, 원형 차트, 영역형 차트 등 다양한 차트 유형을 지원합니다. CreateChart 메서드를 호출할 때 차트 유형을 지정할 수 있으며, 제목, 범례, 데이터 계열을 사용하여 각 차트를 사용자 지정할 수 있습니다.

엑셀 차트에 데이터 계열을 프로그래밍 방식으로 추가하는 방법은 무엇인가요?

IronXL의 AddSeries 메서드를 사용하여 차트에 데이터를 추가할 수 있습니다. 이 메서드는 셀 범위를 매개변수로 받는데, 첫 번째 매개변수는 가로축 값, 두 번째 매개변수는 세로축 값입니다. 여러 개의 계열을 추가하여 다중 계열 차트를 만들 수 있습니다.

C#을 사용하여 Excel에서 선 그래프를 가장 빠르게 만드는 방법은 무엇입니까?

IronXL을 사용하면 단 몇 줄의 코드로 선 그래프를 만들 수 있습니다. CreateChart(ChartType.Line)을 사용하여 차트를 초기화하고, AddSeries()를 사용하여 데이터 범위를 추가하고, SetTitle()을 사용하여 차트 제목을 지정하고, Plot()을 사용하여 워크시트에 차트를 렌더링합니다.

차트 제목이나 범례 위치 같은 차트 속성을 사용자 지정할 수 있나요?

네, IronXL은 Excel 차트를 완벽하게 사용자 지정할 수 있도록 지원합니다. SetTitle() 함수를 사용하여 차트 제목을 추가하고, SetLegendPosition() 함수를 사용하여 범례의 위치(상단, 하단, 왼쪽, 오른쪽)를 지정할 수 있으며, 필요에 따라 데이터 식별을 위해 계열 이름을 지정할 수도 있습니다.

차트를 프로그램으로 생성하려면 Microsoft Excel이 설치되어 있어야 하나요?

아니요, IronXL은 Microsoft Excel 설치 없이 독립적으로 작동합니다. 모든 Excel 파일 작업 및 차트 생성을 자체적으로 처리하므로 Excel을 설치할 수 없는 서버 환경 및 애플리케이션에 적합합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

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 방금 출시되었습니다

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

Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronXl.Excel
샘플을 실행하세요 데이터가 스프레드시트로 변환되는 것을 지켜보세요.