Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): process data #5494

Merged
merged 1 commit into from
Aug 31, 2023
Merged

fix(runtime): process data #5494

merged 1 commit into from
Aug 31, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Aug 31, 2023

数据处理

之前如下的代码无法正常渲染:

export function gaugeDefault(): G2Spec {
  return {
    type: 'view',
    data: {
      value: {
        target: 120,
        total: 400,
        name: 'score',
      },
    },
    children: [{ type: 'gauge' }],
  };
}

原因

原因是因为在 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 会有一些额外的处理。

image

image

@pearmini pearmini merged commit b851ca3 into v5 Aug 31, 2023
@pearmini pearmini deleted the fix/process-data branch August 31, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants