We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Chart ToImage - legend text sometimes is messed up

I have an Excel file with chart, generated with Aspose.Cells. Then I get the chart and convert it to an image:

byte[] excelFile....
using var memoryStream = new MemoryStream(excelFile);
using Workbook excelWorkbook =
    new Workbook(memoryStream, new LoadOptions(LoadFormat.Xlsx));
var chart = excelWorkbook.Worksheets[chartWorksheetIndex].Charts[0];
using var stream = new MemoryStream();
chart.ToImage(stream, imgProps);
using var chartImage = new Bitmap(stream);

In the image, sometimes the legend text is moved/aligned to left or right:
screenshots.zip (163.2 KB)

I’m using Aspose.Cells version 22.1.0.

I’ll appreciate any help or additional info for the issue.

@hvasilev,

Thanks for the screenshots.

Please try using our latest version/fix: Aspose.Cells for .NET v22.8 (Download | NuGet).

If you still find the issue with latest version/fix, kindly do share your Excel file(s) containing the chart, we will check it soon.

PS. please zip the files prior attaching.

I added the files to .zip.

@hvasilev,

You attached zipped archive contains only screenshots. I requested you to provide MS Excel files (containing the charts), so we could evaluate your issue on our end. Please do the needful and zip the Excel files and attach the zipped archive(s) here.

@Amjad_Sahi,

I added the Excel files in xlsx_files.zip (26.5 KB).

@hvasilev,

Please try our latest version/fix: Aspose.Cells for .NET v22.8 (Download | NuGet) . I have tested your scenario/case with latest version using the following sample code with your template files and it works fine:
e.g.
Sample code:

[1]  
           byte[] excelFile = File.ReadAllBytes("e:\\test2\\Segmentation.xlsx");
           var memoryStream = new MemoryStream(excelFile);
           Workbook excelWorkbook = new Workbook(memoryStream, new LoadOptions(LoadFormat.Xlsx));
           Chart chart = excelWorkbook.Worksheets[1].Charts[0];
           ImageOrPrintOptions imgProps = new ImageOrPrintOptions();
           imgProps.ImageType = ImageType.Png;
           var stream = new MemoryStream();
           chart.ToImage(stream, imgProps);
           Bitmap chartImage = new Bitmap(stream);
           chartImage.Save("e:\\test2\\outchart1.png");
[2]
            byte[] excelFile = File.ReadAllBytes("e:\\test2\\Trend.xlsx"); 
            var memoryStream = new MemoryStream(excelFile);
            Workbook excelWorkbook = new Workbook(memoryStream, new LoadOptions(LoadFormat.Xlsx));
            Chart chart = excelWorkbook.Worksheets[0].Charts[0];
            ImageOrPrintOptions imgProps = new ImageOrPrintOptions();
            imgProps.ImageType = ImageType.Png;
            var stream = new MemoryStream();
            chart.ToImage(stream, imgProps);
            Bitmap chartImage = new Bitmap(stream);
            chartImage.Save("e:\\test2\\outchart2.png");

Please find attached the output image files for your reference.
files1.zip (26.1 KB)

@Amjad_Sahi,
Switching to v22.8 didn’t fix it.
Did you try to generate the image several times, because the issue do not appear every time?

@hvasilev,

Could you please share a standalone sample (runnable) code (same as above) to reproduce the issue on our end, we will check it soon.