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).

@amjad.sahi, any updates on this issues?

@JThomas98

There is no update for this issue yet. We will check whether we can get more details about the status of it and give feedback soon.

1 Like

Hi @JThomas98
For this issue, we have corrected some problems with particularly large label biases, and the current results are shown in the figure below, and it didn’t have a bad effect on the labels in other charts that were previously corrected, which will take effect at 25.5.
CELLSNET58208_fix.zip (30.8 KB)

But as I explained to you before, since the positions of these labels are not fixed, Excel has its algorithm, but it is not public.
So currently the output result is not exactly the same as Excel, especially when the labels are very close to each other and overlapping. You can observe the result after 25.5 and see if it is acceptable, and let us know your feedback. If there are still any concerns, or if there are other files or charts with issues, please feel free to contact us, thank you.

@leoluo,
This is good. I’ll run some tests once it’s available and let you know what I think.
Thanks!

@JThomas98,

Sure, please take your time to test your scenarios and test-cases with Aspose.Cells v25.5 once it is published.