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

图例定位左侧后maxRows失效,maxCol显示有问题 #5724

Closed
1 task done
18211365467 opened this issue Nov 2, 2023 · 4 comments
Closed
1 task done

图例定位左侧后maxRows失效,maxCol显示有问题 #5724

18211365467 opened this issue Nov 2, 2023 · 4 comments

Comments

@18211365467
Copy link

18211365467 commented Nov 2, 2023

AntV Open Source Contribution Plan(可选)

  • 我同意将这个 Issue 参与 OSCP 计划

Issue 类型

高级任务

任务介绍

使得以下图表图例正常绘制:

image
/**
 * A recreation of this demo: https://observablehq.com/@d3/bar-chart
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
});

chart.title({
  title: 'Population by age and state',
  subtitle: 'It shows the population of U.S. by age and state.',
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
    format: 'csv',
  })
  .transform({ type: 'dodgeX' })
  .encode('x', 'age')
  .encode('y', 'population')
  .encode('color', 'state')
  .scale('y', { nice: true })
  .axis('y', { labelFormatter: '~s' })
  .legend('color',{
    position:'left',
    maxCols: 3,
  })

chart
  .interaction('tooltip', { shared: true })
  .interaction('elementHighlightByColor', { background: true });

chart.render();

参考说明

出现问题的可能原因:

  • 布局的时候没有考虑到 title
  • 计算 cols 和 rows 的出错
  • 相关代码:
    export function computeLayout(
@pearmini
Copy link
Member

pearmini commented Nov 2, 2023

提供代码

@pearmini pearmini added the V5 label Nov 6, 2023
@18211365467
Copy link
Author

18211365467 commented Nov 7, 2023

/**
 * A recreation of this demo: https://observablehq.com/@d3/grouped-bar-chart
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
  autoFit: true,
});

chart.title({
  title: 'Population by age and state',
  subtitle: 'It shows the population of U.S. by age and state.',
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
    format: 'csv',
  })
  .transform({ type: 'sortX', by: 'y', reverse: true, slice: 6 })
  .transform({ type: 'dodgeX' })
  .encode('x', 'state')
  .encode('y', 'population')
  .encode('color', 'state')
  .scale('y', { nice: true })
  .axis('y', { labelFormatter: '~s' })
  .legend('color',{
    position:'left',
  })
chart
  .interaction('tooltip', { shared: true })
  .interaction('elementHighlightByColor', { background: true });

chart.render();

@BENcorry
Copy link
Contributor

【BENcorry 认领】

@pearmini
Copy link
Member

closed by: #5945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants