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.
数据处理
之前如下的代码无法正常渲染:
原因
原因是因为在 view 层会把非表格数据
{ value: { target: 120, total: 400, name: 'score', } }
处理成{ target: 120, total: 400, name: 'score', }
给 gauge,导致 gauge 处理出错。本质上还是非表格数据必须写成
{ value: data }
的形式,但是表格数据可以直接写成data
。解决办法
view 层处理数据的时候保证数据的结构:如果是表格数据就返回表格数据,否者返回
{ value: data }
形式的数据。结果
额外
至于为啥 G2 官网上代码可以正常运行,是因为 G2 官网的 Chart 为了更好展示 Spec 会有一些额外的处理。