fix(axis): fix chart does not work when using customValues with formatter in time axis label#21352
Merged
plainheart merged 2 commits intoNov 14, 2025
Conversation
|
Thanks for your contribution! |
plainheart
reviewed
Nov 12, 2025
…ter on time axis
Root Cause:
- customValues creates basic ScaleTick objects without time property
- TimeScale formatter code assumed tick.time always exists
- Accessing tick.time.level and tick.time.upperTimeUnit without null checks
Solution Applied:
1. src/util/time.ts:346 - Added null check: level: tick.time ? tick.time.level : 0
2. src/scale/Time.ts:208-212 - Wrapped tick.time access in conditional: if (tick.time) { ... }
Testing:
- Created test/customFormat.html with enhanced styling and custom labels
- Verified fixes work correctly with customValues + formatter combination
Impact:
- Resolves GitHub issue with customValues + formatter combination
- Maintains backward compatibility for existing time axis functionality
- Enables proper custom tick positioning with formatted labels on time axes
0b5860d to
3010cb8
Compare
plainheart
requested changes
Nov 12, 2025
| each(ticks, tick => { | ||
| upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit)); | ||
| maxLevel = Math.max(maxLevel, tick.time.level); | ||
| if (tick.time) { |
Member
There was a problem hiding this comment.
I noticed that TypeScript suppresses this TypeError as per the current tsconfig.json, where the strictNullChecks option is disabled. But if we enable it, there are many errors to be fixed. For simplicity, I agree with your current fix by adding the safeguard.
@100pah How do you think about this?
Contributor
|
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21352@3010cb8 |
- Moved test case from standalone customFormat.html to existing axis-customTicks.html - Added test demonstrating time axis with customValues + formatter combination - Verifies the fix for TypeError when accessing tick.time.level
customValues with formatter in axis label
plainheart
approved these changes
Nov 14, 2025
|
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
customValues with formatter in axis labelcustomValues with formatter in time axis label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix(time-axis): resolve TypeError when using customValues with formatter on time axis
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes TypeError "Cannot read properties of undefined (reading 'level')" when using customValues with formatter function on time axis.
Fixed issues
Details
Before: What was the problem?
When using
customValueswith aformatterfunction on a time axis, ECharts threw a TypeError: "Cannot read properties of undefined (reading 'level')". This occurred because:After: How does it behave after the fixing?
The time axis now properly handles customValues with formatter functions without throwing errors. The fix:
level: tick.time ? tick.time.level : 0if (tick.time) { ... }Testing:
Impact:
Document Info
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
test/customFormat.html demonstrates the fix with customValues + formatter combination
Merging options
Other information
Files Modified:
I am attaching a video for the solution i have added
https://github.com/user-attachments/assets/29d9d047-edab-414d-9512-6dae1cf455ff