Skip to content

Commit 6477656

Browse files
authored
Merge pull request #194 from SyncfusionExamples/940650-SetPieSliceColor
940650-Set pie slice color and pie data label call out in XlsIO
2 parents 85f37a8 + 54b0074 commit 6477656

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed
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}") = "Pie Data Label Call Out", "Pie Data Label Call Out\Pie Data Label Call Out.csproj", "{EEE50E59-2AB6-4EFE-856D-C65C830F3B6B}"
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+
{EEE50E59-2AB6-4EFE-856D-C65C830F3B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EEE50E59-2AB6-4EFE-856D-C65C830F3B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EEE50E59-2AB6-4EFE-856D-C65C830F3B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EEE50E59-2AB6-4EFE-856D-C65C830F3B6B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Create and Edit Charts/Data Labels/.NET/Pie Data Label Call Out/Pie Data Label Call Out/Output/.gitkeep

Whitespace-only changes.
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>Pie_Data_Label_Call_Out</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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.XlsIO;
5+
6+
namespace Pie_Data_Label_CallOuts
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (ExcelEngine excelEngine = new ExcelEngine())
13+
{
14+
IApplication application = excelEngine.Excel;
15+
application.DefaultVersion = ExcelVersion.Xlsx;
16+
IWorkbook workbook = application.Workbooks.Create(1);
17+
IWorksheet worksheet = workbook.Worksheets[0];
18+
19+
//Assigning data to cells
20+
worksheet.Range["A1"].Text = "Category";
21+
worksheet.Range["B1"].Text = "Value";
22+
worksheet.Range["A2"].Text = "Apples";
23+
worksheet.Range["B2"].Number = 30;
24+
worksheet.Range["A3"].Text = "Bananas";
25+
worksheet.Range["B3"].Number = 45;
26+
worksheet.Range["A4"].Text = "Cherries";
27+
worksheet.Range["B4"].Number = 25;
28+
29+
//Add a pie chart to the worksheet
30+
IChartShape chart = worksheet.Charts.Add();
31+
32+
//Set data range for the chart
33+
chart.DataRange = worksheet.Range["A1:B4"];
34+
35+
//Specify chart type
36+
chart.ChartType = ExcelChartType.Pie;
37+
38+
//Set chart properties
39+
chart.IsSeriesInRows = false;
40+
chart.ChartTitle = "Fruit Distribution";
41+
chart.HasLegend = true;
42+
chart.Legend.Position = ExcelLegendPosition.Right;
43+
44+
//Position the chart within the worksheet
45+
chart.TopRow = 6;
46+
chart.LeftColumn = 1;
47+
chart.BottomRow = 20;
48+
chart.RightColumn = 10;
49+
50+
//Customize data label for the first data point
51+
IChartSerie series = chart.Series[0];
52+
series.DataPoints[0].DataLabels.IsCategoryName = true;
53+
series.DataPoints[0].DataLabels.IsValue = true;
54+
55+
//Enable data label callouts for the first data point
56+
series.DataPoints[0].DataLabels.ShowLeaderLines = true;
57+
58+
//Manually resizing data label area using Manual Layout
59+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
60+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;
61+
62+
#region Save
63+
//Saving the workbook
64+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
65+
workbook.SaveAs(outputStream);
66+
#endregion
67+
68+
//Dispose streams
69+
outputStream.Dispose();
70+
}
71+
}
72+
}
73+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# How to display data label callouts in pie charts 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.Drawing;
15+
using Syncfusion.XlsIO;
16+
```
17+
18+
Step 5: Include the below code snippet in **Program.cs** to display data label callouts in pie charts.
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 worksheet = workbook.Worksheets[0];
26+
27+
//Assigning data to cells
28+
worksheet.Range["A1"].Text = "Category";
29+
worksheet.Range["B1"].Text = "Value";
30+
worksheet.Range["A2"].Text = "Apples";
31+
worksheet.Range["B2"].Number = 30;
32+
worksheet.Range["A3"].Text = "Bananas";
33+
worksheet.Range["B3"].Number = 45;
34+
worksheet.Range["A4"].Text = "Cherries";
35+
worksheet.Range["B4"].Number = 25;
36+
37+
//Add a pie chart to the worksheet
38+
IChartShape chart = worksheet.Charts.Add();
39+
40+
//Set data range for the chart
41+
chart.DataRange = worksheet.Range["A1:B4"];
42+
43+
//Specify chart type
44+
chart.ChartType = ExcelChartType.Pie;
45+
46+
//Set chart properties
47+
chart.IsSeriesInRows = false;
48+
chart.ChartTitle = "Fruit Distribution";
49+
chart.HasLegend = true;
50+
chart.Legend.Position = ExcelLegendPosition.Right;
51+
52+
//Position the chart within the worksheet
53+
chart.TopRow = 6;
54+
chart.LeftColumn = 1;
55+
chart.BottomRow = 20;
56+
chart.RightColumn = 10;
57+
58+
//Customize data label for the first data point
59+
IChartSerie series = chart.Series[0];
60+
series.DataPoints[0].DataLabels.IsCategoryName = true;
61+
series.DataPoints[0].DataLabels.IsValue = true;
62+
63+
//Enable data label callouts for the first data point
64+
series.DataPoints[0].DataLabels.ShowLeaderLines = true;
65+
66+
//Manually resizing data label area using Manual Layout
67+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.09;
68+
chart.Series[0].DataPoints[0].DataLabels.Layout.ManualLayout.Top = 0.01;
69+
70+
#region Save
71+
//Saving the workbook
72+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
73+
workbook.SaveAs(outputStream);
74+
#endregion
75+
76+
//Dispose streams
77+
outputStream.Dispose();
78+
}
79+
```

0 commit comments

Comments
 (0)