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

【v5】柱线混合,前一个 mark 的 dodgeX tranform 会影响后一个的 Mark #5250

Closed
Deathsteps opened this issue Jun 29, 2023 · 6 comments · Fixed by #5528
Closed

Comments

@Deathsteps
Copy link
Contributor

问题描述

线图在分组柱形后面,配置 color 映射。作图失败
image

对调代码后,渲染正常
image

对调后虽然可以渲染,但柱图遮住了线图不符合要求

期望结果

tranfrom 应该只影响对应的 mark。

如何重现

官方代码修改

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

const data = [
  { time: '10:10', call: 4, waiting: 2, people: 2, type: 'a' },
  { time: '10:10', call: 2, waiting: 6, people: 3, type: 'b' },
  { time: '10:20', call: 13, waiting: 2, people: 5, type: 'a' },
  { time: '10:20', call: 9, waiting: 9, people: 1, type: 'b' },
  { time: '10:30', call: 5, waiting: 2, people: 3, type: 'a' },
  { time: '10:30', call: 8, waiting: 2, people: 1, type: 'b' },
  { time: '10:40', call: 13, waiting: 1, people: 2, type: 'a' },
  { time: '10:40', call: 13, waiting: 1, people: 2, type: 'b' },
];

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

chart.data(data);

chart
  .interval()
  .transform({ "type": "dodgeX" })
  .encode('x', 'time')
  .encode('y', 'waiting')
  .encode('color', 'type')
  .axis('y', { title: 'Waiting', style: { titleFill: '#5B8FF9' } });

chart
  .line()
  .encode('x', 'time')
  .encode('y', 'people')
  .encode('shape', 'smooth')
  // 多系列
  // .encode('color', 'type')
  // 默认图例
  // .encode('color', () => 'people');

chart.render();

额外信息

  • G2 5.0.14 版本
@pearmini
Copy link
Member

问题原因是 interval 和 line 都有 series 通道,但是两者推断的比例尺类型不同,有冲突,把 line 的 series 比例尺设置为独立的即可。

chart
  .line()
  .encode('x', 'time')
  .encode('y', 'people')
  .encode('shape', 'smooth')
  .encode('color', 'type')
  .scale('series', { independent:true })

@pearmini
Copy link
Member

内部有没有办法默认避免这种情况?不对 series 通道进行比例尺合并合理吗?

@Deathsteps
Copy link
Contributor Author

内部有没有办法默认避免这种情况?不对 series 通道进行比例尺合并合理吗?

合并的收益是什么。series independent 会有其它副作用吗?
我理解组合场景会有很多,是只有 dodgeX tranform 有影响还是其它 transform 也会有影响。我看 select 和 group 等 transform case 好像没有类似问题,不知道图形差异还是 transform 差异导致。

@pearmini
Copy link
Member

这和 transform 的关系不大,dodgeX 做的事情支持把 color 通道赋给了 series 通道而已。

series independent 会有其它副作用吗?

这个问题我还得思考一下,如果没有问题,可以默认 independent。

@pearmini
Copy link
Member

pearmini commented Jul 3, 2023

这个例子就需要默认同步 series 的比例尺:https://g2.antv.antgroup.com/examples/analysis/group/#bar-multi-measure

@pearmini
Copy link
Member

pearmini commented Jul 3, 2023

相同的问题:#5076

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

Successfully merging a pull request may close this issue.

2 participants