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

Free Support Forum - aspose.com

Issues when accessing/modifying X-axis from an Excel chart using Aspose.Cells

Hi,

In Excel, I’m able to choose the X-axis, modify the major unit and therefore change the number of tickmarks on the chart (steps attached in a gif in the attachment zip).

However, when I did the same with Aspose.Cells, I found several issues reading/writing/rendering the values.

Code:

var workbook = new Workbook(@".\test.xlsx");
var chart = workbook.Worksheets[0].Charts[0];
chart.Calculate();

var axis = chart.CategoryAxis;
Console.Write(axis.AxisLabels.Count); // ISSUE #1: incorrectly returned 27 where it was only 13

// changing the major unit to reduce the tickmarks to 5 (equivalent in the gif doing in MS Excel attached)
axis.MajorUnit = 91;
chart.Calculate();
Console.Write(axis.AxisLabels.Count); // correctly returned 5

workbook.Save(@".\out.xlsx"); // ISSUE #2: the number of tickmarks in the document is not actually changed (13)
// ISSUE #3 if I convert the chart to image using Aspose.Cells, more tickmarks are present in the image (27)

The issue doesn’t seem to happen with Y-axis where changing MajorUnit on the chart will successfully change the tickmarks. Also, it doesn’t seem to happen with other charts on X-axis.

I’ve attached the test files and the steps using Excel for your reference. Could you please help me take a look?

test.zip (400.8 KB)

Thanks,

@ServerSide527,
We have observed the first two issues and have logged them in our database for further analysis and a fix. We will notify you here once any update is ready to share.

This issue is logged as:
CELLSNET-47627- Issues when accessing/modifying X-axis of an Excel chart using Aspose.Cells

Regarding the third issue where you mentioned that while converting the chart to image, you get 27 tick marks, is not reproduced. I get 5 tick marks as expected. You may please try the scenario with the latest version and share the feedback. I have used the following line of code to convert the chart to an image.

chart.ToImage(@"C:\test\Cells_218946\PieChart.out.emf", ImageFormat.Emf);

Chart.out.zip (11.8 KB)

Hi @ahsaniqbalsidiqui

Thanks for the information.

For the 3rd issue, you will need to close reopen the saved workbook by using
var newWorkbook = new Workbook(@".\output.xlsx");
then render it to the image.

Could you try that? The output image example was provided in my previous attachment.

Thanks,

@ServerSide527,
Thank you for the additional information. This issue is also logged with the ticket and will be considered during the analysis.

@ServerSide527,
This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@ServerSide527,
Please try the latest fix 21.5.1.
Aspose.Cells21.5.1 For .Net2_AuthenticodeSigned.Zip (5.5 MB)
Aspose.Cells21.5.1 For .Net4.0.Zip (5.5 MB)
Aspose.Cells21.5.1 For .NetStandard20.Zip (5.5 MB)

The issues you have found earlier (filed as CELLSNET-47627) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao

Hi @ahsaniqbalsidiqui,

After testing with Aspose.Cells 22.2 I can see Issues #1 and #3 are fixed.
However, issue #2 is still present, seems like Aspose is not changing the axis units to Days: Changing axis manually vs Aspose’s output comparison.png (82.1 KB)

Could you please have a look and let me know if I’m doing something wrong? This is the code I’m using along the resources in test.zip of my first comment:

var workbook = new Workbook(@".\test.xlsx");
var chart = workbook.Worksheets[0].Charts[0];
chart.Calculate();

var axis = chart.CategoryAxis;
Console.Write(axis.AxisLabels.Count);

// changing the major unit to reduce the tickmarks to 5 (equivalent in the gif doing in MS Excel attached)
axis.MajorUnitScale = TimeUnit.Days; // axis.AxisLabels.Count returns 1 without this line now
axis.MajorUnit = 91;
chart.Calculate();
Console.Write(axis.AxisLabels.Count); // correctly returned 5

workbook.Save(@".\out.xlsx"); // ISSUE #2: the number of tickmarks in the document is not actually changed (13)

Thanks,

@ServerSide527,

Thanks for the screenshot with details.

Please notice, I am able to reproduce the issue as you mentioned. The Axis units are not changed in the output XLSX file. I noticed the second issue is still present, it seems like Aspose.Cells is not changing the axis units to Days properly in the output file. I have logged a separate ticket with an id “CELLSNET-50596” for your issue. We will look into it soon.

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

@ServerSide527,

Please try the following code for your reference:

var workbook = new Workbook(@".\test.xlsx");
var chart = workbook.Worksheets[0].Charts[0];
chart.Calculate();

var axis = chart.CategoryAxis;
Console.Write(axis.AxisLabels.Count);

// changing the major unit to reduce the tickmarks to 5 (equivalent in the gif doing in MS Excel attached)
axis.CategoryType = CategoryType.TimeScale;
axis.MajorUnitScale = TimeUnit.Days; // axis.AxisLabels.Count returns 1 without this line now
axis.MajorUnit = 91;
chart.Calculate();
Console.Write(axis.AxisLabels.Count); // correctly returned 5

workbook.Save(@".\out.xlsx"); // ISSUE #2: the number of tickmarks in the document is not actually changed (13)

@Eric.wang thanks for your suggestion.

I saw that we have to manually change the category type to TimeScale with Aspose. However, in MS Excel, the category is automatic and we don’t need to force it to TimeScale to get the proper output.

image.png (23.3 KB)

You can also check the gif file in the zip file attached with my initial post where I only had to change the major unit scale and major unit values, without changing the category type.

Since Aspose also mimics the behaviour from Office, can it behave the same so we don’t have to manually change the category type?

@ServerSide527,

Thanks for sharing the screenshot and your concerns.

We have logged it against your ticket into our database. We will evaluate and get back to you soon.

@ServerSide527,

This is to inform you that we have fixed your issue precisely now. The fix will be included in our regular release Aspose.Cells for .NET v22.4 which is scheduled to be published in the second week of April, 2022.

The issues you have found earlier (filed as CELLSNET-50596) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi