Skip to content

Commit b056457

Browse files
authored
Merge pull request #182 from SyncfusionExamples/941204-SwitchChartSeriesExample
941204-FAQ on how to switch chart series to show it as vertical from horizontal
2 parents 9dabb3d + c3b3ac3 commit b056457

File tree

10 files changed

+337
-0
lines changed

10 files changed

+337
-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>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# How to switch chart series data interpretation from horizontal (rows) to vertical (columns) in Excel?
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 switch chart series data interpretation from horizontal (rows) to vertical (columns) in Excel.
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 for chart
28+
sheet.Range["A1"].Text = "Year";
29+
sheet.Range["B1"].Text = "2022";
30+
sheet.Range["C1"].Text = "2023";
31+
sheet.Range["D1"].Text = "2024";
32+
33+
sheet.Range["A2"].Text = "Sales";
34+
sheet.Range["B2"].Number = 1000;
35+
sheet.Range["C2"].Number = 1500;
36+
sheet.Range["D2"].Number = 1800;
37+
38+
sheet.Range["A3"].Text = "Profit";
39+
sheet.Range["B3"].Number = 200;
40+
sheet.Range["C3"].Number = 300;
41+
sheet.Range["D3"].Number = 400;
42+
43+
//Create a Chart
44+
IChartShape chart = sheet.Charts.Add();
45+
46+
//Set chart type
47+
chart.ChartType = ExcelChartType.Bar_Clustered;
48+
49+
//Set data range in the worksheet
50+
chart.DataRange = sheet.Range["A1:D3"];
51+
52+
//Set series orientation from rows to columns
53+
chart.IsSeriesInRows = false;
54+
55+
//Positioning the chart in the worksheet
56+
chart.TopRow = 9;
57+
chart.LeftColumn = 1;
58+
chart.BottomRow = 22;
59+
chart.RightColumn = 8;
60+
61+
#region Save
62+
//Saving the workbook
63+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
64+
workbook.SaveAs(outputStream);
65+
#endregion
66+
67+
//Dispose streams
68+
outputStream.Dispose();
69+
}
70+
```
71+
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}") = "Switch chart series orientation", "Switch chart series orientation\Switch chart series orientation.csproj", "{07E4DE10-07B9-4832-B093-A30959B90B5D}"
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+
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Output/.gitkeep

Whitespace-only changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
5+
namespace Switch_Chart_Series_Orientation
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 for chart
19+
sheet.Range["A1"].Text = "Year";
20+
sheet.Range["B1"].Text = "2022";
21+
sheet.Range["C1"].Text = "2023";
22+
sheet.Range["D1"].Text = "2024";
23+
24+
sheet.Range["A2"].Text = "Sales";
25+
sheet.Range["B2"].Number = 1000;
26+
sheet.Range["C2"].Number = 1500;
27+
sheet.Range["D2"].Number = 1800;
28+
29+
sheet.Range["A3"].Text = "Profit";
30+
sheet.Range["B3"].Number = 200;
31+
sheet.Range["C3"].Number = 300;
32+
sheet.Range["D3"].Number = 400;
33+
34+
//Create a Chart
35+
IChartShape chart = sheet.Charts.Add();
36+
37+
//Set chart type
38+
chart.ChartType = ExcelChartType.Bar_Clustered;
39+
40+
//Set data range in the worksheet
41+
chart.DataRange = sheet.Range["A1:D3"];
42+
43+
//Set series orientation from rows to columns
44+
chart.IsSeriesInRows = false;
45+
46+
//Positioning the chart in the worksheet
47+
chart.TopRow = 9;
48+
chart.LeftColumn = 1;
49+
chart.BottomRow = 22;
50+
chart.RightColumn = 8;
51+
52+
#region Save
53+
//Saving the workbook
54+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
55+
workbook.SaveAs(outputStream);
56+
#endregion
57+
58+
//Dispose streams
59+
outputStream.Dispose();
60+
}
61+
}
62+
}
63+
}
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>Switch_chart_series_orientation</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)