fix(custom): resolve api.value() NaN issue for key-value data format #21342
+359
−1
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.
Resolves critical issue where api.value() returned NaN for object-based data while array-based data worked correctly in custom series renderItem function.
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes api.value() function in custom series to properly handle key-value data format [{x:100, y:200}] by adding fallback to raw data access when internal store access fails.
Fixed issues
Critical bug where custom series api.value() returned NaN for key-value object data format while array format worked correctly.
Details
Before: What was the problem?
Root Cause: The
valuefunction insrc/chart/custom/CustomView.ts(lines 755-783) only attempted to access ECharts' internal data store viadata.getItemModel(dataIndex).get(dim). For key-value data format[{x: 100, y: 200}], the dimension mapping failed in the store, causingapi.value('x')andapi.value(0)to returnNaN.Technical Issue:
{x: 100, y: 200}weren't properly mapped to store dimensions[[100, 200]]worked because store mapping succeededImpact:
api.value('x')returnedNaNinstead of100api.value(0)returnedNaNinstead of100After: How does it behave after the fixing?
Solution: Enhanced the
valuefunction with intelligent fallback mechanism:data.getItemModel(dataIndex).get(dim)api.value('x')→ searches raw object keysapi.value(0)→ maps to dimension order for objectsTechnical Implementation: