Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Aug 22, 2023 5:40 am

I want to have a doughnut chart with data labels outside with leader lines, but it's not supporting data labels out side, I am trying to do the same with Pie chart with data labels outside of Pie chart and by overlaying an empty circle
is it possible? can I have a chart over other chart with transparency?

Image

sPandavula
 
Posts: 4
Joined: Tue Aug 22, 2023 5:25 am

Tue Aug 22, 2023 10:30 am

Hi, Thank you for your inquiry.
You can refer to the following C# code to achieve your requirement, and please note that the position of white round is set according to your chart position.
Code: Select all
static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.Version = ExcelVersion.Version2013;
            //Get worksheet
            Worksheet sheet = workbook.Worksheets[0];
            sheet.Name = "share";
            sheet.GridLinesVisible = false;
            //Add data to worksheet
            sheet.Range["A1"].Value = "test1";
            sheet.Range["A2"].Value = "Z1";
            sheet.Range["A3"].Value = "Z2";
            sheet.Range["A4"].Value = "Z3";
            sheet.Range["A5"].Value = "Z4";
            sheet.Range["A6"].Value = "Z5";
            sheet.Range["A7"].Value = "Z6";
            sheet.Range["A8"].Value = "Z7";
            sheet.Range["A9"].Value = "Z8";
            sheet.Range["B1"].Value = "test2";
            sheet.Range["B2"].NumberValue = 4;
            sheet.Range["B3"].NumberValue = 5;
            sheet.Range["B4"].NumberValue = 8;
            sheet.Range["B5"].NumberValue = 9;
            sheet.Range["B6"].NumberValue = 11;
            sheet.Range["B7"].NumberValue = 18;
            sheet.Range["B8"].NumberValue = 22;
            sheet.Range["B9"].NumberValue = 23;

            //Create pie chart
            Chart chart = sheet.Charts.Add(ExcelChartType.Pie);

            //Specify the data area used to generate the chart
            chart.DataRange = sheet.Range["B2:B9"];
            chart.SeriesDataFromRange = false;

            //Specify the location of the chart
            chart.LeftColumn = 4;
            chart.TopRow = 2;
            chart.RightColumn = 12;
            chart.BottomRow = 22;
            chart.ChartTitle = "share";
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 10;
            //Set values for chart series
            foreach (ChartSerie cs1 in chart.Series)
            {
                cs1.DataPoints.DefaultDataPoint.DataLabels.HasPercentage = true;
                cs1.DataPoints.DefaultDataPoint.DataLabels.Position = DataLabelPositionType.Outside;
            }
            //Add oval shape1
            IOvalShape ovalShape1 = sheet.OvalShapes.AddOval(10, 7, 100, 100);
            ovalShape1.Line.Weight = 0;
            //Fill shape with solid color
            ovalShape1.Fill.FillType = ShapeFillType.SolidColor;
            ovalShape1.Fill.ForeColor = Color.White;
           
           //Save
            workbook.SaveToFile(@"E:\\测试\\DoughnutChart1.xlsx");
        }


These are my test screenshots:
1.png
1.png (17.91 KiB) Viewed 2315 times

If my code doesn’t help you, please offer your code and file to help us do further investigation, you can attach here or send it to us via email ([email protected]). Thank you in advance.

Sincerely,
Ula
E-iceblue support team
Last edited by Ula.wang on Fri Aug 25, 2023 2:36 am, edited 1 time in total.
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Wed Aug 23, 2023 6:23 am

Hi Ula,
Thanks for response, I tried with the given code, but inner empty circle did not render for me, only Pie. My licensed version is Spire.Office 5.1.0, does this solution work with my version? I also tried with a free version of Spire.Office 8.8.0, but it's also not working. Any help would be great thanks

sPandavula
 
Posts: 4
Joined: Tue Aug 22, 2023 5:25 am

Wed Aug 23, 2023 8:06 am

Hi

Thank you for your inquiry.
This solution I provided yesterday is not applicable to Spire.Office 5.1.0. I have found that according to your license file, you can use versions before Spire.Office 5.12.8, I have tested it and make sure that Spire.Office 5.12.8 can produce an internal blank circle for you.
In addition, you can download the Spire.Office 5.12.8 through NuGet.
If you have any issue, just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Thu Aug 24, 2023 3:35 pm

Thanks Ula, yes Spire.Office 5.12.8 version is able to show circle in output excel file.
We are trying to save images with
Code: Select all
workbook1.SaveChartAsImage(sheet1)
, saved images doesn't have circle. If any tools or workaround for saving as images please suggest.
Thank you

sPandavula
 
Posts: 4
Joined: Tue Aug 22, 2023 5:25 am

Fri Aug 25, 2023 6:07 am

Hi

Thank you for your inquiry.
I have tested the code you provided and encounter the same issue as you.
please refer to the following code and have a test:
Code: Select all
sheet.SaveToImage(@"E:\\Test\\ExceltoImage.png", ImageFormat.Png);

Here is a screenshot of my test screen:
3.png
3.png (22.85 KiB) Viewed 2265 times

If my code doesn’t help you, please offer the following information to help us do further investigation. Thank you in advance.
1)Your input excel file, you can attach here or send it to us via email ([email protected]).
2)Your full test code that can reproduce your issue.
3)Application type, such as Console App, .NET Framework 4.8.
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit).

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Tue Sep 12, 2023 8:08 am

Hi

I would like to know if the solution we have provided has helped you solved the problem you have encountered, and our team expected to have more communication with you.
If my solution doesn’t help you, please offer the following information to help us do further investigation. Thank you in advance.
1)Your input excel file, you can attach here or send it to us via email ([email protected]).
2) Your full test code that can reproduce your issue.
3) Application type, such as Console App, .NET Framework 4.8.
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit).

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.XLS