From 79b2ce08b2c5a1395815388a2b1ccaa831287efd Mon Sep 17 00:00:00 2001 From: KarthikaSF4773 Date: Tue, 13 May 2025 01:45:26 +0530 Subject: [PATCH 1/2] 941204-SwitchChartSeriesExample --- .../Switch chart series orientation/README.md | 71 +++++++++++++++++++ .../Switch chart series orientation.sln | 22 ++++++ .../Output/.gitkeep | 0 .../Program.cs | 63 ++++++++++++++++ .../Switch chart series orientation.csproj | 21 ++++++ 5 files changed, 177 insertions(+) create mode 100644 FAQ/Chart/.NET/Switch chart series orientation/README.md create mode 100644 FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation.sln create mode 100644 FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Output/.gitkeep create mode 100644 FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Program.cs create mode 100644 FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Switch chart series orientation.csproj diff --git a/FAQ/Chart/.NET/Switch chart series orientation/README.md b/FAQ/Chart/.NET/Switch chart series orientation/README.md new file mode 100644 index 00000000..c76a47a4 --- /dev/null +++ b/FAQ/Chart/.NET/Switch chart series orientation/README.md @@ -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(); +} +``` + diff --git a/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation.sln b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation.sln new file mode 100644 index 00000000..e1f4a940 --- /dev/null +++ b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation.sln @@ -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 diff --git a/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Output/.gitkeep b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Program.cs b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Program.cs new file mode 100644 index 00000000..bfc55632 --- /dev/null +++ b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Program.cs @@ -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(); + } + } + } +} diff --git a/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Switch chart series orientation.csproj b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Switch chart series orientation.csproj new file mode 100644 index 00000000..db365da9 --- /dev/null +++ b/FAQ/Chart/.NET/Switch chart series orientation/Switch chart series orientation/Switch chart series orientation.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Switch_chart_series_orientation + enable + enable + + + + + + + + + Always + + + + From c3b3ac3a57e0cd675edd30dcad9ff570953b414e Mon Sep 17 00:00:00 2001 From: KarthikaSF4773 Date: Wed, 14 May 2025 09:29:29 +0530 Subject: [PATCH 2/2] 261673-How to show leader lines on Excel chart using XlsIO? --- FAQ/Chart/.NET/Show leader line/README.md | 62 +++++++++++++++++++ .../Show leader line/Show leader line.sln | 22 +++++++ .../Show leader line/Output/.gitkeep | 0 .../Show leader line/Program.cs | 55 ++++++++++++++++ .../Show leader line/Show leader line.csproj | 21 +++++++ 5 files changed, 160 insertions(+) create mode 100644 FAQ/Chart/.NET/Show leader line/README.md create mode 100644 FAQ/Chart/.NET/Show leader line/Show leader line.sln create mode 100644 FAQ/Chart/.NET/Show leader line/Show leader line/Output/.gitkeep create mode 100644 FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs create mode 100644 FAQ/Chart/.NET/Show leader line/Show leader line/Show leader line.csproj diff --git a/FAQ/Chart/.NET/Show leader line/README.md b/FAQ/Chart/.NET/Show leader line/README.md new file mode 100644 index 00000000..40c4a0bc --- /dev/null +++ b/FAQ/Chart/.NET/Show leader line/README.md @@ -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(); +} +``` \ No newline at end of file diff --git a/FAQ/Chart/.NET/Show leader line/Show leader line.sln b/FAQ/Chart/.NET/Show leader line/Show leader line.sln new file mode 100644 index 00000000..2d8e9685 --- /dev/null +++ b/FAQ/Chart/.NET/Show leader line/Show leader line.sln @@ -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 diff --git a/FAQ/Chart/.NET/Show leader line/Show leader line/Output/.gitkeep b/FAQ/Chart/.NET/Show leader line/Show leader line/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs b/FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs new file mode 100644 index 00000000..f60933ef --- /dev/null +++ b/FAQ/Chart/.NET/Show leader line/Show leader line/Program.cs @@ -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(); + } + } + } +} \ No newline at end of file diff --git a/FAQ/Chart/.NET/Show leader line/Show leader line/Show leader line.csproj b/FAQ/Chart/.NET/Show leader line/Show leader line/Show leader line.csproj new file mode 100644 index 00000000..3362ec5e --- /dev/null +++ b/FAQ/Chart/.NET/Show leader line/Show leader line/Show leader line.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Show_leader_line + enable + enable + + + + + + + + + Always + + + +