CELLSNET-57840: Placement of values in/around pie chart

Hi,
I tested the new version of aspose for the issue previously recorded as CELLSNET-57840.
In my testing I found that this particular chart where the placement is really off.

I’ve used the range “Demographics!D273:O305” and the code used is:

Document RepDoc = new Document();
DocumentBuilder Builder = new DocumentBuilder(RepDoc);
using (Workbook TemplateWB = new Workbook(dir + @"\Test_04112025\Chart_Template.xlsm"))
{
    Worksheet sourceWS = TemplateWB.Worksheets["Demographics"];

    //Set print area
    sourceWS.PageSetup.PrintArea = $"D273:O305";
    sourceWS.PageSetup.LeftMargin = 0;
    sourceWS.PageSetup.RightMargin = 0;
    sourceWS.PageSetup.TopMargin = 0;
    sourceWS.PageSetup.BottomMargin = 0;
    // Clear any header/footer as they'll be captured when converting the worksheet to image
    sourceWS.PageSetup.ClearHeaderFooter();

    // Set OnePagePerSheet option as true
    ImageOrPrintOptions options = new ImageOrPrintOptions
    {
        OnePagePerSheet = true,
        ImageType = Aspose.Cells.Drawing.ImageType.OfficeCompatibleEmf,
        HorizontalResolution = 100,
        VerticalResolution = 100,
        OnlyArea = true
    };

    // Take the image of your worksheet
    SheetRender Render = new SheetRender(sourceWS, options);
    // Create a stream to save the image in
    MemoryStream ImgStream = new MemoryStream();
    Render.ToImage(0, ImgStream); //Returns an image of the cell range if an accuarate cell range is suppiled
    if (ImgStream != MemoryStream.Null)
    {                    
        // Insert this image into the place of the old shape.
        Shape newOleShape = Builder.InsertImage(ImgStream);
        Aspose.Words.PageSetup PS = Builder.CurrentSection.PageSetup;
                            double PageWidth = PS.PageWidth - PS.LeftMargin - PS.RightMargin;
                            if (PageWidth < newOleShape.Width)
                            {
                                newOleShape.Width = PageWidth;
                            }
    }
}
RepDoc.Save(dir + @"\Test_04112025\Word_Template.docx");

Test_04112025.zip (2.7 MB)

@JThomas98

It seems you are experiencing issues with the placement of values in your pie chart when using Aspose.Cells. To address the placement of chart elements, you can manipulate the position and size of the chart using the properties provided by the Aspose.Cells API.

To adjust the position and size of your pie chart, you can use the Chart.ChartObject property, which allows you to set the X and Y coordinates, as well as the height and width of the chart. Here’s an example of how you can modify your existing code to reposition and resize the chart:

// Assuming you have already created your chart
Aspose.Cells.Charts.Chart chart = sourceWS.Charts[0]; // Access the first chart

// Set the new position and size
chart.ChartObject.X = 100; // Set the X position
chart.ChartObject.Y = 100; // Set the Y position
chart.ChartObject.Width = 400; // Set the width
chart.ChartObject.Height = 300; // Set the height

Make sure to adjust the X and Y values according to your layout requirements. This should help in correcting the placement of the values around your pie chart.

If you continue to face issues, consider checking the chart data and ensuring that the data labels are correctly set. You can also refer to the documentation for more details on manipulating chart properties and elements [1].

Sources:
[1]: Manipulate Position Size and Designer Chart

@JThomas98,

Thanks for the template Excel file and output Word file.

After initial testing, I am able to reproduce the issue as you mentioned by using your template Excel file and sample code snippet. I found data label placements for charts are off when rendering sheet to image.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-58208

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you, @amjad.sahi!

@JThomas98,

You are welcome. We will keep you posted with updates on it (once available).