Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions FAQ/Chart/.NET/Show leader line/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# How to show the leader line on Excel chart using XlsIO?

Step 1: Create a New C# Console Application Project.

Step 2: Name the Project.

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).

Step 4: Include the following namespaces in the **Program.cs** file.

```csharp
using System;
using System.IO;
using Syncfusion.XlsIO;
```

Step 5: Include the below code snippet in **Program.cs** to show the leader line on Excel chart.

```csharp
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];

//Add data
sheet.Range["A1"].Text = "Fruit";
sheet.Range["B1"].Text = "Quantity";
sheet.Range["A2"].Text = "Apple";
sheet.Range["A3"].Text = "Banana";
sheet.Range["A4"].Text = "Cherry";
sheet.Range["B2"].Number = 40;
sheet.Range["B3"].Number = 30;
sheet.Range["B4"].Number = 30;

//Add a Pie chart
IChart chart = sheet.Charts.Add();
chart.ChartType = ExcelChartType.Pie;
chart.DataRange = sheet.Range["A1:B4"];
chart.IsSeriesInRows = false;
chart.ChartTitle = "Fruit Distribution";

//Enable data labels with values, and leader lines
IChartSerie series = chart.Series[0];
series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
series.DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;

//Manually resizing data label area using Manual Layout
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
}
```
22 changes: 22 additions & 0 deletions FAQ/Chart/.NET/Show leader line/Show leader line.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Show leader line", "Show leader line\Show leader line.csproj", "{2E869A2C-3942-4463-A81E-6B86B4CDD538}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E869A2C-3942-4463-A81E-6B86B4CDD538}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Empty file.
55 changes: 55 additions & 0 deletions FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using Syncfusion.XlsIO;

namespace Show_Leader_Line
{
class Program
{
static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];

//Add data
sheet.Range["A1"].Text = "Fruit";
sheet.Range["B1"].Text = "Quantity";
sheet.Range["A2"].Text = "Apple";
sheet.Range["A3"].Text = "Banana";
sheet.Range["A4"].Text = "Cherry";
sheet.Range["B2"].Number = 40;
sheet.Range["B3"].Number = 30;
sheet.Range["B4"].Number = 30;

//Add a Pie chart
IChart chart = sheet.Charts.Add();
chart.ChartType = ExcelChartType.Pie;
chart.DataRange = sheet.Range["A1:B4"];
chart.IsSeriesInRows = false;
chart.ChartTitle = "Fruit Distribution";

//Enable data labels with values, and leader lines
IChartSerie series = chart.Series[0];
series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
series.DataPoints.DefaultDataPoint.DataLabels.ShowLeaderLines = true;

//Manually resizing data label area using Manual Layout
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Show_leader_line</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
71 changes: 71 additions & 0 deletions FAQ/Chart/.NET/Switch chart series orientation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# How to switch chart series data interpretation from horizontal (rows) to vertical (columns) in Excel?

Step 1: Create a New C# Console Application Project.

Step 2: Name the Project.

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).

Step 4: Include the following namespaces in the **Program.cs** file.

```csharp
using System;
using System.IO;
using Syncfusion.XlsIO;
```

Step 5: Include the below code snippet in **Program.cs** to switch chart series data interpretation from horizontal (rows) to vertical (columns) in Excel.

```csharp
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];

//Add data for chart
sheet.Range["A1"].Text = "Year";
sheet.Range["B1"].Text = "2022";
sheet.Range["C1"].Text = "2023";
sheet.Range["D1"].Text = "2024";

sheet.Range["A2"].Text = "Sales";
sheet.Range["B2"].Number = 1000;
sheet.Range["C2"].Number = 1500;
sheet.Range["D2"].Number = 1800;

sheet.Range["A3"].Text = "Profit";
sheet.Range["B3"].Number = 200;
sheet.Range["C3"].Number = 300;
sheet.Range["D3"].Number = 400;

//Create a Chart
IChartShape chart = sheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.Bar_Clustered;

//Set data range in the worksheet
chart.DataRange = sheet.Range["A1:D3"];

//Set series orientation from rows to columns
chart.IsSeriesInRows = false;

//Positioning the chart in the worksheet
chart.TopRow = 9;
chart.LeftColumn = 1;
chart.BottomRow = 22;
chart.RightColumn = 8;

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
}
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Switch chart series orientation", "Switch chart series orientation\Switch chart series orientation.csproj", "{07E4DE10-07B9-4832-B093-A30959B90B5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07E4DE10-07B9-4832-B093-A30959B90B5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.IO;
using Syncfusion.XlsIO;

namespace Switch_Chart_Series_Orientation
{
class Program
{
static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];

//Add data for chart
sheet.Range["A1"].Text = "Year";
sheet.Range["B1"].Text = "2022";
sheet.Range["C1"].Text = "2023";
sheet.Range["D1"].Text = "2024";

sheet.Range["A2"].Text = "Sales";
sheet.Range["B2"].Number = 1000;
sheet.Range["C2"].Number = 1500;
sheet.Range["D2"].Number = 1800;

sheet.Range["A3"].Text = "Profit";
sheet.Range["B3"].Number = 200;
sheet.Range["C3"].Number = 300;
sheet.Range["D3"].Number = 400;

//Create a Chart
IChartShape chart = sheet.Charts.Add();

//Set chart type
chart.ChartType = ExcelChartType.Bar_Clustered;

//Set data range in the worksheet
chart.DataRange = sheet.Range["A1:D3"];

//Set series orientation from rows to columns
chart.IsSeriesInRows = false;

//Positioning the chart in the worksheet
chart.TopRow = 9;
chart.LeftColumn = 1;
chart.BottomRow = 22;
chart.RightColumn = 8;

#region Save
//Saving the workbook
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
workbook.SaveAs(outputStream);
#endregion

//Dispose streams
outputStream.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Switch_chart_series_orientation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>