Excel 차트를 만드는 방법 C#
IronXL 사용하여 C#에서 Excel 차트를 생성하려면 CreateChart() 메서드를 호출하고, AddSeries()으로 데이터 시리즈를 추가하고, 제목 및 범례를 구성한 후, Plot() 메서드로 플롯하여 코드 몇 줄로 완벽한 Excel 시각화를 완성할 수 있습니다.
IronXL에서 열 차트를 생성하세요: 단일 워크시트 메서드를 사용하여 차트를 만들고, 데이터 시리즈를 추가하고, 제목과 범례를 설정하고, 플롯한 다음 저장하세요. IronXL의 기능에 대한 포괄적인 개요를 보려면 시작 개요 페이지를 방문하세요.
-
1IronXL를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
IChart chart = worksheet.CreateChart(ChartType.Column, 5, 5, 20, 10); chart.AddSeries("A2:A7", "B2:B7"); chart.SetTitle("Sales Overview").SetLegendPosition(LegendPosition.Bottom).Plot(); workbook.SaveAs("SalesChart.xlsx");Dim chart As IChart = worksheet.CreateChart(ChartType.Column, 5, 5, 20, 10) chart.AddSeries("A2:A7", "B2:B7") chart.SetTitle("Sales Overview").SetLegendPosition(LegendPosition.Bottom).Plot() workbook.SaveAs("SalesChart.xlsx")Dim chart As IChart = worksheet.CreateChart(ChartType.Column, 5, 5, 20, 10) chart.AddSeries("A2:A7", "B2:B7") chart.SetTitle("Sales Overview").SetLegendPosition(LegendPosition.Bottom).Plot() workbook.SaveAs("SalesChart.xlsx") -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronXL 사용을 시작해보세요 무료 체험
최소 워크플로우 (6단계)
- Excel 차트를 만들 Excel 라이브러리를 설치하세요.
- 기존 Excel 파일을
Workbook객체로 로드합니다. CreateChart로 차트를 생성합니다.- 차트의 제목과 범례를 설정하세요.
Plot메서드를 호출합니다.- Excel 파일에
Workbook를 저장합니다.
프로그램 방식으로 .NET에서 Excel 차트 생성하기
- Excel 그래프를 프로그래밍 방식으로 생성하기
- 제목과 범례를 가진 시리즈 추가하기
1단계
IronXL을 설치하여 Excel 차트 생성하는 방법은?
Visual Studio의 NuGet 패키지 관리자를 사용하여 IronXL을 설치하세요:
- 프로젝트 메뉴 선택
- NuGet 패키지 관리
IronXL.Excel검색- 설치
이 설치는 프로그래밍 방식으로 Excel 차트 생성에 필요한 모든 도구를 제공합니다. IronXL은 열, 선, 원형, 막대, 영역 및 분산형 차트를 포함한 다양한 차트 유형을 지원합니다.
NuGet 패키지 관리자를 사용하는 이유는?
Developer Command Prompt에 다음 명령을 입력할 수도 있습니다:
다른 설치 방법은 무엇인가요?
또는 여기에서 다운로드하십시오: https://ironsoftware.com/csharp/excel/packages/IronXL.zip
설치 후, IronXL을 사용하여 새 Excel 파일을 처음부터 생성하거나 기존 스프레드시트로 작업할 수 있으며, 이는 신규 프로젝트와 기존 시스템 통합 모두에 적합합니다.
튜토리얼 사용법
.NET에서 프로그래밍 방식으로 Excel 차트를 생성하는 방법은?
Excel 스프레드시트에 다음 데이터를 추가하세요:
차트를 생성하기 전에 데이터가 적절히 정리되어 있는지 확인하세요. IronXL은 기존 스프레드시트를 로드할 수 있으며, 프로그래밍 방식으로 생성할 수도 있습니다. 이 라이브러리는 XLS, XLSX, CSV, TSV를 포함한 다양한 Excel 파일 형식을 지원합니다.
Excel 차트를 위해 필요한 네임스페이스는 무엇인가요?
IronXL에서 Excel 차트 작업에 필요한 네임스페이스를 추가하세요:
using IronXL;
using IronXL.Drawing.Charts;using IronXL;
using IronXL.Drawing.Charts;Imports IronXL
Imports IronXL.Drawing.ChartsImports IronXL
Imports IronXL.Drawing.Charts이 네임스페이스는 모든 차트 관련 기능에 대한 액세스를 제공합니다. IronXL 네임스페이스는 기본 워크북 및 워크시트 작업을 포함하며, IronXL.Drawing.Charts는 차트 생성 및 사용자 지정 기능을 처리합니다.
내 차트에 여러 데이터 시리즈를 어떻게 추가하나요?
IronXL을 사용하여 Excel 그래프를 프로그래밍 방식으로 생성하는 코드를 추가하세요:
using IronXL;
using IronXL.Drawing.Charts;
// Load the existing Excel workbook
WorkBook wb = WorkBook.Load("Chart_Ex.xlsx");
// Use the default worksheet from the workbook
WorkSheet ws = wb.DefaultWorkSheet;
// Create a column chart at the specified range of cells
var chart = ws.CreateChart(ChartType.Column, 10, 15, 25, 20);
// Define the range for the x-axis data
const string xAxis = "A2:A7";
// Add a series for the chart using data in the range and give it a title from the first row
var series = chart.AddSeries(xAxis, "B2:B7");
series.Title = ws["B1"].StringValue;
// Add another series
series = chart.AddSeries(xAxis, "C2:C7");
series.Title = ws["C1"].StringValue;
// Add a third series
series = chart.AddSeries(xAxis, "D2:D7");
series.Title = ws["D1"].StringValue;
// Set the chart title
chart.SetTitle("Column Chart");
// Position the legend at the bottom of the chart
chart.SetLegendPosition(LegendPosition.Bottom);
// Plot the chart with the provided data
chart.Plot();
// Save the workbook with the newly added chart
wb.SaveAs("Exported_Column_Chart.xlsx");using IronXL;
using IronXL.Drawing.Charts;
// Load the existing Excel workbook
WorkBook wb = WorkBook.Load("Chart_Ex.xlsx");
// Use the default worksheet from the workbook
WorkSheet ws = wb.DefaultWorkSheet;
// Create a column chart at the specified range of cells
var chart = ws.CreateChart(ChartType.Column, 10, 15, 25, 20);
// Define the range for the x-axis data
const string xAxis = "A2:A7";
// Add a series for the chart using data in the range and give it a title from the first row
var series = chart.AddSeries(xAxis, "B2:B7");
series.Title = ws["B1"].StringValue;
// Add another series
series = chart.AddSeries(xAxis, "C2:C7");
series.Title = ws["C1"].StringValue;
// Add a third series
series = chart.AddSeries(xAxis, "D2:D7");
series.Title = ws["D1"].StringValue;
// Set the chart title
chart.SetTitle("Column Chart");
// Position the legend at the bottom of the chart
chart.SetLegendPosition(LegendPosition.Bottom);
// Plot the chart with the provided data
chart.Plot();
// Save the workbook with the newly added chart
wb.SaveAs("Exported_Column_Chart.xlsx");Imports IronXL
Imports IronXL.Drawing.Charts
' Load the existing Excel workbook
Dim wb As WorkBook = WorkBook.Load("Chart_Ex.xlsx")
' Use the default worksheet from the workbook
Dim ws As WorkSheet = wb.DefaultWorkSheet
' Create a column chart at the specified range of cells
Dim chart = ws.CreateChart(ChartType.Column, 10, 15, 25, 20)
' Define the range for the x-axis data
Const xAxis As String = "A2:A7"
' Add a series for the chart using data in the range and give it a title from the first row
Dim series = chart.AddSeries(xAxis, "B2:B7")
series.Title = ws("B1").StringValue
' Add another series
series = chart.AddSeries(xAxis, "C2:C7")
series.Title = ws("C1").StringValue
' Add a third series
series = chart.AddSeries(xAxis, "D2:D7")
series.Title = ws("D1").StringValue
' Set the chart title
chart.SetTitle("Column Chart")
' Position the legend at the bottom of the chart
chart.SetLegendPosition(LegendPosition.Bottom)
' Plot the chart with the provided data
chart.Plot()
' Save the workbook with the newly added chart
wb.SaveAs("Exported_Column_Chart.xlsx")Imports IronXL
Imports IronXL.Drawing.Charts
' Load the existing Excel workbook
Dim wb As WorkBook = WorkBook.Load("Chart_Ex.xlsx")
' Use the default worksheet from the workbook
Dim ws As WorkSheet = wb.DefaultWorkSheet
' Create a column chart at the specified range of cells
Dim chart = ws.CreateChart(ChartType.Column, 10, 15, 25, 20)
' Define the range for the x-axis data
Const xAxis As String = "A2:A7"
' Add a series for the chart using data in the range and give it a title from the first row
Dim series = chart.AddSeries(xAxis, "B2:B7")
series.Title = ws("B1").StringValue
' Add another series
series = chart.AddSeries(xAxis, "C2:C7")
series.Title = ws("C1").StringValue
' Add a third series
series = chart.AddSeries(xAxis, "D2:D7")
series.Title = ws("D1").StringValue
' Set the chart title
chart.SetTitle("Column Chart")
' Position the legend at the bottom of the chart
chart.SetLegendPosition(LegendPosition.Bottom)
' Plot the chart with the provided data
chart.Plot()
' Save the workbook with the newly added chart
wb.SaveAs("Exported_Column_Chart.xlsx")CreateChart 메서드는 차트 유형 및 위치(왼쪽 열, 상단 행, 오른쪽 열, 하단 행)에 대한 매개 변수를 받습니다. 이 위치 지정은 셀 좌표를 사용하여 워크시트 내에 차트를 정확하게 배치합니다. 단일 워크시트에 여러 차트를 생성하거나 다른 시트에 분산시킬 수 있습니다.
데이터 시리즈 작업 시 IronXL은 표준 Excel 표기법을 사용하여 셀 범위를 참조할 수 있습니다. 이로 인해 Excel에 익숙한 개발자가 프로그래밍 방식으로 차트를 생성하는 것이 직관적입니다. 또한, 차트를 Excel 수식과 결합하여 데이터 변경 시 자동으로 업데이트되는 동적 시각화를 만들 수 있습니다.
다른 차트 유형을 어떻게 만들 수 있나요?
IronXL은 열 차트 외에도 다양한 차트 유형을 지원합니다. 다음은 사용자 정의 스타일을 사용하여 선 그래프를 생성하는 예입니다:
// Create a line chart for trend analysis
var lineChart = ws.CreateChart(ChartType.Line, 10, 22, 25, 32);
// Add data series with smooth lines
var trendSeries = lineChart.AddSeries("A2:A7", "B2:B7");
trendSeries.Title = "Q1 Sales Trend";
// Customize chart appearance
lineChart.SetTitle("Quarterly Sales Trend Analysis");
lineChart.SetLegendPosition(LegendPosition.Right);
// You can also create a column chart with multiple series
var comboChart = ws.CreateChart(ChartType.Column, 27, 15, 42, 25);
comboChart.AddSeries("A2:A7", "B2:B7"); // First column series
comboChart.AddSeries("A2:A7", "C2:C7"); // Second column series
comboChart.Plot();// Create a line chart for trend analysis
var lineChart = ws.CreateChart(ChartType.Line, 10, 22, 25, 32);
// Add data series with smooth lines
var trendSeries = lineChart.AddSeries("A2:A7", "B2:B7");
trendSeries.Title = "Q1 Sales Trend";
// Customize chart appearance
lineChart.SetTitle("Quarterly Sales Trend Analysis");
lineChart.SetLegendPosition(LegendPosition.Right);
// You can also create a column chart with multiple series
var comboChart = ws.CreateChart(ChartType.Column, 27, 15, 42, 25);
comboChart.AddSeries("A2:A7", "B2:B7"); // First column series
comboChart.AddSeries("A2:A7", "C2:C7"); // Second column series
comboChart.Plot();' Create a line chart for trend analysis
Dim lineChart = ws.CreateChart(ChartType.Line, 10, 22, 25, 32)
' Add data series with smooth lines
Dim trendSeries = lineChart.AddSeries("A2:A7", "B2:B7")
trendSeries.Title = "Q1 Sales Trend"
' Customize chart appearance
lineChart.SetTitle("Quarterly Sales Trend Analysis")
lineChart.SetLegendPosition(LegendPosition.Right)
' You can also create a column chart with multiple series
Dim comboChart = ws.CreateChart(ChartType.Column, 27, 15, 42, 25)
comboChart.AddSeries("A2:A7", "B2:B7") ' First column series
comboChart.AddSeries("A2:A7", "C2:C7") ' Second column series
comboChart.Plot()' Create a line chart for trend analysis
Dim lineChart = ws.CreateChart(ChartType.Line, 10, 22, 25, 32)
' Add data series with smooth lines
Dim trendSeries = lineChart.AddSeries("A2:A7", "B2:B7")
trendSeries.Title = "Q1 Sales Trend"
' Customize chart appearance
lineChart.SetTitle("Quarterly Sales Trend Analysis")
lineChart.SetLegendPosition(LegendPosition.Right)
' You can also create a column chart with multiple series
Dim comboChart = ws.CreateChart(ChartType.Column, 27, 15, 42, 25)
comboChart.AddSeries("A2:A7", "B2:B7") ' First column series
comboChart.AddSeries("A2:A7", "C2:C7") ' Second column series
comboChart.Plot()최종 차트 출력은 어떻게 생겼나요?
Workbook 객체와 Worksheet 객체가 생성됩니다. Worksheet 객체의 CreateChart 메서드를 호출하여 차트 유형과 차트 위치를 지정합니다. 차트의 시리즈는 제목 및 범례와 함께 추가됩니다.

그림 2 - 차트 출력
생성된 차트는 데이터의 명확한 시각적 표현을 제공합니다. IronXL은 모든 복잡한 Excel XML 형식화를 백그라운드에서 처리하여 비즈니스 로직에 집중할 수 있도록 해줍니다. 차트 생성에 대한 더 많은 예는 Excel 차트 예제 페이지를 확인하세요.
고급 차트 사용자 정의
기본 차트 작성 외에도 IronXL은 광범위한 사용자 정의 옵션을 제공합니다. 색상을 수정하고, 데이터 레이블을 추가하며, 축 스케일을 조정하고 다양한 형식 옵션을 적용할 수 있습니다. 라이브러리의 저장 및 내보내기 기능은 차트가 다양한 Excel 형식 및 버전 간에 올바르게 보존되도록 보장합니다.
대용량 데이터셋 작업 시 차트 작성 전에 페이지 매김 또는 데이터 필터링을 구현하는 것을 고려하세요. 이 방법은 최적의 성능을 보장하고 혼란스러운 시각화를 방지합니다. IronXL의 효율적인 메모리 관리를 통해 성능 저하 없이 대규모 Excel 파일을 다룰 수 있습니다.
라이브러리 바로가기
IronXL API 참조 문서
Learn more and share how to merge, unmerge, and work with cells in Excel spreadsheets using the handy IronXL API 참조 문서.
IronXL API 참조 문서자주 묻는 질문
C#를 사용하여 프로그래밍 방식으로 Excel 차트를 어떻게 생성합니까?
IronXL 라이브러리를 사용하면 C#에서 프로그래밍 방식으로 Excel 차트를 생성할 수 있습니다. 먼저 Excel 파일을 Workbook 객체에 로드합니다. 그런 다음, CreateChart 메서드를 사용하여 차트의 유형과 위치를 지정합니다. AddSeries 메서드를 사용하여 데이터 시리즈를 추가한 다음, 차트의 제목과 범례를 설정하고 Plot을 호출하여 차트를 렌더링합니다.
IronXL에서는 Excel 차트에 데이터 시리즈를 추가하기 위해 어떤 메서드를 사용합니까?
IronXL에서는 AddSeries 메서드를 사용하여 Excel 차트에 데이터를 추가할 수 있습니다. 이 메서드는 x축 및 y축 데이터에 대한 셀 범위를 지정해야 합니다. 또한 worksheet의 값을 사용하여 데이터 시리즈 제목을 설정할 수 있습니다.
Excel 차트 생성을 위해 IronXL을 어떻게 설치합니까?
IronXL은 Visual Studio의 NuGet 패키지 관리자를 통해 설치할 수 있습니다. 프로젝트 메뉴로 이동한 후, Manage NuGet Packages를 선택하고 IronXL.Excel을 검색하여 설치합니다. 이렇게 하면 프로그래밍 방식으로 Excel 차트를 생성하는 데 필요한 모든 도구가 제공됩니다.
IronXL이 지원하는 차트 유형은 무엇입니까?
IronXL은 열, 선, 파이, 막대, 면, 산포 차트 등 다양한 차트 유형을 지원합니다. C#에서 IronXL에서 제공하는 메서드를 사용하여 이 차트들을 프로그래밍 방식으로 생성하고 사용자 정의할 수 있습니다.
IronXL을 사용하여 하나의 차트에 여러 데이터 시리즈를 어떻게 추가합니까?
IronXL에서 하나의 차트에 여러 데이터 시리즈를 추가하려면 CreateChart 함수와 함께 AddSeries 메서드를 사용합니다. 각 시리즈에 대한 데이터 범위를 지정하고 worksheet 셀 값을 사용하여 개별 제목을 설정합니다. 차트에 필요한 만큼의 데이터 시리즈를 추가할 수 있습니다.
IronXL은 성능 문제 없이 대용량 Excel 파일을 처리할 수 있습니까?
네, IronXL은 메모리를 효율적으로 관리하도록 설계되어 있어 대용량 Excel 파일을 성능 저하 없이 처리할 수 있습니다. 최적의 성능을 위해 차트를 생성하기 전에 페이징 또는 데이터 필터링을 고려할 수 있습니다.
IronXL을 사용하여 Excel 차트를 생성할 때 필요한 네임스페이스는 무엇입니까?
IronXL을 사용하여 Excel 차트를 생성할 때 필요한 네임스페이스는 IronXL 및 IronXL.Drawing.Charts입니다. IronXL 네임스페이스는 기본적인 워크북 및 워크시트 작업을 가능하게 하고, IronXL.Drawing.Charts는 차트 생성 및 사용자 정의를 가능하게 합니다.
IronXL이 지원하는 Excel 차트를 위한 파일 형식은 무엇입니까?
IronXL은 XLS, XLSX, CSV, TSV 등 여러 Excel 파일 형식을 지원합니다. 이러한 유연성 덕분에 다양한 형식으로 차트를 생성할 수 있어, 다른 Excel 버전 및 사용 사례와의 호환성이 보장됩니다.
IronXL에서 차트 외형을 어떻게 사용자 정의할 수 있습니까?
IronXL은 차트의 색상 수정, 데이터 라벨 추가, 축 스케일 조정, 다양한 서식 스타일 적용 등의 광범위한 사용자 정의 옵션을 제공합니다. 이를 통해 시각적으로 매력적이고 정보 제공이 가능한 Excel 차트를 만들 수 있습니다.
Excel 차트 생성을 위해 IronXL 라이브러리를 사용하는 이점은 무엇입니까?
IronXL은 C#에서 프로그래밍 방식으로 Excel 차트를 생성하고 관리하는 과정을 간소화합니다. 복잡한 Excel XML 서식을 처리하고, 다양한 차트 유형을 지원하며, 광범위한 사용자 정의를 제공하고, 대용량 파일에 대한 효율적인 메모리 관리를 제공하여 개발자가 비즈니스 로직에 집중할 수 있도록 합니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.
