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

【问题】请问有办法实现x轴多级分组图表吗 #4724

Closed
KuduroJS opened this issue Mar 3, 2023 · 3 comments
Closed

【问题】请问有办法实现x轴多级分组图表吗 #4724

KuduroJS opened this issue Mar 3, 2023 · 3 comments

Comments

@KuduroJS
Copy link

KuduroJS commented Mar 3, 2023

image

类似效果如上图。

以及,求一个有官方或者前端小伙伴的g2交流群。

谢谢。

@pearmini
Copy link
Member

pearmini commented Mar 4, 2023

v5 版本这里有一个简单的例子:

image

import { Chart } from '@antv/g2';

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

const data = [
  { sex: 'male', age: 30, class: 'A', single: false },
  { sex: 'male', age: 25, class: 'A', single: true },
  { sex: 'male', age: 60, class: 'B', single: false },
  { sex: 'male', age: 35, class: 'B', single: true },
  { sex: 'female', age: 40, class: 'A', single: false },
  { sex: 'female', age: 28, class: 'A', single: true },
  { sex: 'female', age: 34, class: 'B', single: false },
  { sex: 'female', age: 50, class: 'B', single: true },
];

const facet = chart
  .facetRect()
  .data(data)
  .encode('x', 'sex')
  .legend('color', { position: 'right', size: 50 })
  .axis('x', { position: 'bottom', tick: false });

facet
  .interval()
  .attr('paddingBottom', 10)
  .transform({ type: 'dodgeX' })
  .encode('x', 'class')
  .encode('color', 'single')
  .encode('y', 'age')
  .axis('x', { title: '' })
  .attr('frame', false);

chart.render();

@pearmini
Copy link
Member

pearmini commented Mar 4, 2023

@KuduroJS
Copy link
Author

KuduroJS commented Mar 4, 2023

v5 版本这里有一个简单的例子:

image

import { Chart } from '@antv/g2';

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

const data = [
  { sex: 'male', age: 30, class: 'A', single: false },
  { sex: 'male', age: 25, class: 'A', single: true },
  { sex: 'male', age: 60, class: 'B', single: false },
  { sex: 'male', age: 35, class: 'B', single: true },
  { sex: 'female', age: 40, class: 'A', single: false },
  { sex: 'female', age: 28, class: 'A', single: true },
  { sex: 'female', age: 34, class: 'B', single: false },
  { sex: 'female', age: 50, class: 'B', single: true },
];

const facet = chart
  .facetRect()
  .data(data)
  .encode('x', 'sex')
  .legend('color', { position: 'right', size: 50 })
  .axis('x', { position: 'bottom', tick: false });

facet
  .interval()
  .attr('paddingBottom', 10)
  .transform({ type: 'dodgeX' })
  .encode('x', 'class')
  .encode('color', 'single')
  .encode('y', 'age')
  .axis('x', { title: '' })
  .attr('frame', false);

chart.render();

谢谢您的回复,我看一下相关文档和示例。

说到v5版本,我们公司正在开发一个低代码的BI系统,虽然我很希望用v5版本,但在生产环境可以吗,是否稳定,离正式版还有多久?希望听听您的意见。

另外,您的群链接失效了hhh,:)

@KuduroJS KuduroJS closed this as completed Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants