Chart.ToImage() breaks Data Labels

Hello,
Please see the attached input and output files. The output file is generated with this code block. When image is taken of the chart named “ScreenShot”, the DataLabels in the chart are changed into a bad state. To see the issue open the output.xlsx file and notice that the data label on the first bar is “50.0%”. Now save the document and watch the data label change to “-50.0% - 40.0%”. Looking at the XML spec it appears that the DataLabels are changing from a cell range reference to a static text value and all of the columns worth of data label are being placed into the first column. This adverse behavior only occurs after using the ToImage method on the Chart.

var workbook = new Workbook("input.xlsx");

workbook.Worksheets[0].Charts["ScreenShot"]
    .ToImage(new MemoryStream(), new ImageOrPrintOptions()
    {
        ChartImageType = ImageFormat.Png,
        ImageType = Aspose.Cells.Drawing.ImageType.Png,
        Transparent = true
    });

workbook.Save("output.xlsx", SaveFormat.Xlsx);

files.zip (49.5 KB)

Thank You,
-Andy

@weissa,

Thanks for the sample files.

I opened your input.xlsx file into MS Excel 2013 and 2016 and both versions show that data labels are: “-50.0% - 40.0%”, see the screenshot attached.
sc_shot1.png (33.1 KB)

So, it is not an issue in the output XLSX file as both input and output files display same data labels.

@Amjad_Sahi,

Thank you for the quick response.

Open the output.xlsx file and see this is correct:
image.png (676 Bytes)

Now save the file and see the change which is incorrect:

image.png (3.2 KB)

I believe if you use CalculateFormula before saving the output file then it’ll save like this too. That’s what happens in our product. We determined that this state only exists if we take an image of the chart.

Thanks,
-Andy

@weissa,

I still could not find the issue. I opened the output file (generated by the code with your input file). I found no difference at all. I used MS Excel 2016 to open the file into it, see the screenshot attached.
sc_shot12.png (28.6 KB)

Did you open the output file into MS Excel 2013 or 2016 and what is the result? Which MS Excel vision you are using?

@Amjad_Sahi,

I downloaded the file I posted to double check and I can reproduce.

My Excel version is: Microsoft® Excel® for Microsoft 365 MSO (Version 2203 Build 16.0.15028.20152) 64-bit

-Andy

@weissa,

We will check the issue in Excel 365 soon. But could you please check to open the output file into MS Excel 2013 or 2016 and let us know your results.

@weissa,

I did test your scenario/case again using your input.xlsx file with the following code. Please note, I am using our latest version of Aspose.Cells for .NET v22.3, please try it if you are not already using it.
e.g.
Sample code:

var workbook = new Workbook("e:\\test2\\input.xlsx");
workbook.Worksheets[0].Charts["ScreenShot"]
.ToImage(new MemoryStream(), new ImageOrPrintOptions()
 {
         ChartImageType = ImageFormat.Png,
         ImageType = Aspose.Cells.Drawing.ImageType.Png,
         Transparent = true
});
            
workbook.Save("e:\\test2\\output.xlsx", SaveFormat.Xlsx);

Please find attached the output file generated on my end. I opened it into MS Excel 2007, 2013, 2016 and Excel 365. All versions show data labels fine. Please open the output XLSX (attached in the archive) into MS Excel on your end and let us know the results with some screenshots.
files1.zip (24.2 KB)

@Amjad_Sahi,

We were using version .21 which exhibited the problem. I can confirm it’s working correctly with version 22.3. Next time we’ll test in the latest version first. I’ll confirm with the customer that this is working properly in the latest version and will report back.

As always thank you for your support.

-Andy

@weissa,

Good to know that your issue is sorted out by the new version/fix. Feel free to write us back if you have further queries or comments, we will be happy to assist you soon.