Skip to content

Commit c3b3ac3

Browse files
261673-How to show leader lines on Excel chart using XlsIO?
1 parent 79b2ce0 commit c3b3ac3

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# How to show the leader line on Excel chart using XlsIO?
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
```
16+
17+
Step 5: Include the below code snippet in **Program.cs** to show the leader line on Excel chart.
18+
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
IWorkbook workbook = application.Workbooks.Create(1);
25+
IWorksheet sheet = workbook.Worksheets[0];
26+
27+
//Add data
28+
sheet.Range["A1"].Text = "Fruit";
29+
sheet.Range["B1"].Text = "Quantity";
30+
sheet.Range["A2"].Text = "Apple";
31+
sheet.Range["A3"].Text = "Banana";
32+
sheet.Range["A4"].Text = "Cherry";
33+
sheet.Range["B2"].Number = 40;
34+
sheet.Range["B3"].Number = 30;
35+
sheet.Range["B4"].Number = 30;
36+
37+
//Add a Pie chart
38+
IChart chart = sheet.Charts.Add();
39+
chart.ChartType = ExcelChartType.Pie;
40+
chart.DataRange = sheet.Range["A1:B4"];
41+
chart.IsSeriesInRows = false;
42+
chart.ChartTitle = "Fruit Distribution";
43+
44+
//Enable data labels with values, and leader lines
45+
IChartSerie series = chart.Series[0];
46+
series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
47+
series.DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;
48+
49+
//Manually resizing data label area using Manual Layout
50+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
51+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;
52+
53+
#region Save
54+
//Saving the workbook
55+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
56+
workbook.SaveAs(outputStream);
57+
#endregion
58+
59+
//Dispose streams
60+
outputStream.Dispose();
61+
}
62+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Show leader line", "Show leader line\Show leader line.csproj", "{2E869A2C-3942-4463-A81E-6B86B4CDD538}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

FAQ/Chart/.NET/Show leader line/Show leader line/Output/.gitkeep

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
5+
namespace Show_Leader_Line
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (ExcelEngine excelEngine = new ExcelEngine())
12+
{
13+
IApplication application = excelEngine.Excel;
14+
application.DefaultVersion = ExcelVersion.Xlsx;
15+
IWorkbook workbook = application.Workbooks.Create(1);
16+
IWorksheet sheet = workbook.Worksheets[0];
17+
18+
//Add data
19+
sheet.Range["A1"].Text = "Fruit";
20+
sheet.Range["B1"].Text = "Quantity";
21+
sheet.Range["A2"].Text = "Apple";
22+
sheet.Range["A3"].Text = "Banana";
23+
sheet.Range["A4"].Text = "Cherry";
24+
sheet.Range["B2"].Number = 40;
25+
sheet.Range["B3"].Number = 30;
26+
sheet.Range["B4"].Number = 30;
27+
28+
//Add a Pie chart
29+
IChart chart = sheet.Charts.Add();
30+
chart.ChartType = ExcelChartType.Pie;
31+
chart.DataRange = sheet.Range["A1:B4"];
32+
chart.IsSeriesInRows = false;
33+
chart.ChartTitle = "Fruit Distribution";
34+
35+
//Enable data labels with values, and leader lines
36+
IChartSerie series = chart.Series[0];
37+
series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
38+
series.DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;
39+
40+
//Manually resizing data label area using Manual Layout
41+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
42+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;
43+
44+
#region Save
45+
//Saving the workbook
46+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
47+
workbook.SaveAs(outputStream);
48+
#endregion
49+
50+
//Dispose streams
51+
outputStream.Dispose();
52+
}
53+
}
54+
}
55+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Show_leader_line</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Output\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)