Chart ToImage() doesn't save all labels of a pie chart

Hello,

We have encountered the following issue. Saving the pie chart from our workbook as image ends in losing a label from the original chart.

Here is the following code used to reproduce this issue, along with the attached file:
----------
var workbook = new Workbook(“testFile.xlsx”);
var worksheet = workbook.Worksheets[0];
const string chartName = “ProductionPie”;

var chart =
worksheet.Charts.FirstOrDefault(x => chartName.Equals(x.Name, StringComparison.OrdinalIgnoreCase));
if (chart == null)
return;

chart.ToImage().Save(@“out.png”);
----------

InternalId: 21485

Best regards,
Jean-Alexandru Stanescu
Junior Developer
IBM Romania

Hi,


Thanks for the template file and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found Chart.ToImage() doesn’t save all labels of the Pie chart, i noticed “Asia Pacific & Middle East…” label is not shown in the rendered image.
e.g
Sample code:

var workbook = new Workbook(“e:\test2\testFile.xlsx”);
var worksheet = workbook.Worksheets[0];

var chart = worksheet.Charts[0];
if (chart == null)
return;

chart.ToImage().Save(@“e:\test2\out1.png”);

I have logged a ticket with an id “CELLSNET-44023” for your issue. We will look into your issue soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,

Thanks for using Aspose.Cells.

The position of label that is not seen in the chart is automatic. If the labels can be placed well in the slice of pie, the position will be Inside, otherwise Outside.

For this label, Excel is Inside, Aspose is Outside. As it is too complex to figure out the proper position when the position is automatic, we cannot fix the issues now. You may make the label shown by setting the plot area’s color and labels’ font color different using the following code segment before converting to image.

C#
chart.ChartArea.Area.ForegroundColor = Color.FromArgb(85, 142, 213);

chart.ToImage().Save(@“out.png”);

@ibmromania,

Please try our latest version Aspose.Cells 21.6.0.

If you find any issue, please provide the source Excel file to help us analyze it.