Srajan-Sanjay-Saxena opened a new pull request, #21352:
URL: https://github.com/apache/echarts/pull/21352
fix(time-axis): resolve TypeError when using customValues with formatter on
time axis
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### 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
- Resolves GitHub issue with customValues + formatter combination causing
runtime errors
## Details
### Before: What was the problem?
When using `customValues` with a `formatter` function on a time axis,
ECharts threw a TypeError: "Cannot read properties of undefined (reading
'level')". This occurred because:
- customValues creates basic ScaleTick objects without time property
- TimeScale formatter code assumed tick.time always exists
- Code accessed tick.time.level and tick.time.upperTimeUnit without null
checks
### After: How does it behave after the fixing?
The time axis now properly handles customValues with formatter functions
without throwing errors. The fix:
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 with npm run prepare && npm run build
- Confirmed both fixes present in distribution files
Impact:
- Maintains backward compatibility for existing time axis functionality
- Enables proper custom tick positioning with formatted labels on time axes
## Document Info
- [x] This PR doesn't relate to document changes
- [ ] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### Security Checking
- [x] This PR uses security-sensitive Web APIs.
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
test/customFormat.html demonstrates the fix with customValues + formatter
combination
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
Files Modified:
- src/util/time.ts (leveledFormat function)
- src/scale/Time.ts (getTicks method)
- test/customFormat.html (enhanced styling demo)
- dist/* (rebuilt distribution files)
I am attaching a video for the solution i have added
https://github.com/user-attachments/assets/29d9d047-edab-414d-9512-6dae1cf455ff
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]