Fix X-Axis MajorUnit and MinorUnit configuration for line charts #1723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When configuring X-Axis parameters on LINE charts using
Add-ExcelChart, theXMajorUnitandXMinorUnitparameters were being ignored, even thoughXMinValueandXMaxValueworked correctly. This issue affected line charts and other chart types that use category axes.Root Cause
LINE charts use a category axis (catAx) for the X-axis in the underlying Excel Open XML format, while the Y-axis uses a value axis (valAx). When setting
XMajorUnitandXMinorUnitthrough the EPPlus API, these values are stored in memory but EPPlus doesn't serialize them to the XML for category axes—only value axes have these properties properly written to the file.Solution
This PR adds code to manually insert the
<c:majorUnit>and<c:minorUnit>XML elements into the category axis node when these parameters are specified. The fix:XMajorUnitorXMinorUnitparameters are provided-PassThruChanges
Public/Add-ExcelChart.ps1: Added XML manipulation code (51 lines) to set majorUnit/minorUnit on category axes__tests__/Add-ExcelChart-XAxis.Tests.ps1: New comprehensive test suite (8 tests) covering various scenariosTesting
All tests passing:
Affected Chart Types
This fix applies to chart types that use category axes:
Chart types using value axes for X-axis (XYScatter, etc.) were not affected by the bug and continue to work as before.
Example
Fixes #[issue_number]
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.