antvis/G2

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

Deathsteps posted onGitHub

问题描述

线图在分组柱形后面,配置 color 映射。作图失败 <img width="1069" alt="image" src="https://github.com/antvis/G2/assets/1549118/358ab722-83f2-4148-a842-40e6daaa0eb6">

对调代码后,渲染正常 <img width="1106" alt="image" src="https://github.com/antvis/G2/assets/1549118/1ee2d389-d0c2-4b54-a4b4-4749c3dad4e1">

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

期望结果

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 版本

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

chart
  .line()
  .encode('x', 'time')
  .encode('y', 'people')
  .encode('shape', 'smooth')
  .encode('color', 'type')
  .scale('series', { independent:true })
posted by pearmini almost 2 years ago

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

posted by pearmini almost 2 years ago

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

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

posted by Deathsteps almost 2 years ago

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

series independent 会有其它副作用吗?

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

posted by pearmini almost 2 years ago

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

posted by pearmini almost 2 years ago
posted by pearmini almost 2 years ago

Fund this Issue

$0.00
Funded

Pull requests