I’m using Aspose.Slides.NET6.CrossPlatform in .NET. When I try to add a line chart and get its vertical axis’ actual major unit after validating chart layout, it always return 1, while the actual minor unit seems correct (which makes it ridiculous that the major unit is even less than the minor unit).
using (Presentation pres = new Presentation())
{
// Add a line chart
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Line, 100, 100, 500, 400);
// Fill with data with large values
IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook;
IChartSeries series = chart.ChartData.Series[0];
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A1", 1000));
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A2", 3000));
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A3", 2000));
// Get vertical axis and set its units as auto
IAxis verticalAxis = chart.Axes.VerticalAxis;
verticalAxis.IsAutomaticMajorUnit = true;
verticalAxis.IsAutomaticMinorUnit = true;
// Force to calculate chart layout
chart.ValidateChartLayout();
// Output actual units
Console.WriteLine($"Actual Major Unit: {verticalAxis.ActualMajorUnit}");
Console.WriteLine($"Actual Minor Unit: {verticalAxis.ActualMinorUnit}");
}
It appears you are facing an issue where the ActualMajorUnit of the vertical axis in your line chart consistently returns 1, while the ActualMinorUnit reflects the expected value. This can be perplexing, particularly when the major unit is less than the minor unit.
Here are several factors to consider:
Automatic Units: When both IsAutomaticMajorUnit and IsAutomaticMinorUnit are set to true, the chart engine automatically determines the units based on the provided data. In certain scenarios, especially with large values, the engine may not compute the major unit accurately, resulting in unexpected outcomes like the one you are experiencing.
Data Range: Verify that the data range you are using is suitable for the chart type. If the data points are too close together or if the range is not well-defined, the chart may default to a major unit of 1.
Chart Validation: While you are correctly calling chart.ValidateChartLayout(), if the issue persists, consider manually setting the MajorUnit to a specific value after validation to see if that resolves the problem.
Here’s a revised version of your code that sets a specific major unit after validation:
using (Presentation pres = new Presentation())
{
// Add a line chart
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.Line, 100, 100, 500, 400);
// Fill with data with large values
IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook;
IChartSeries series = chart.ChartData.Series[0];
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A1", 1000));
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A2", 3000));
series.DataPoints.AddDataPointForLineSeries(workbook.GetCell(0, "A3", 2000));
// Get vertical axis and set its units as automatic
IAxis verticalAxis = chart.Axes.VerticalAxis;
verticalAxis.IsAutomaticMajorUnit = true;
verticalAxis.IsAutomaticMinorUnit = true;
// Force the chart to calculate its layout
chart.ValidateChartLayout();
// Optionally set a specific major unit
verticalAxis.MajorUnit = 1000; // Adjust this value based on your data
// Output actual units
Console.WriteLine($"Actual Major Unit: {verticalAxis.ActualMajorUnit}");
Console.WriteLine($"Actual Minor Unit: {verticalAxis.ActualMinorUnit}");
}
If the issue persists after trying these suggestions, it may be advisable to report this as a potential bug to the Aspose support team, especially since similar issues have been noted in other versions.
Please feel free to reach out if you have any further questions or require additional assistance!
And I think, even if the engine does calculate the actual major unit as 1, in that case it should also calculate the actual minor unit as 1. But now the major unit is even less than the minor unit.
@C8H17OH,
Thank you for describing the issue. I have reproduced the problem where the ActualMajorUnit property of a vertical chart axis returns 1. We apologize for any inconvenience caused.
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): SLIDESNET-45117
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.
The issues you found earlier (filed as SLIDESNET-45117) have been resolved in Aspose.Slides for .NET 25.10 (ZIP, MSI, NuGet, Cross-platform).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.