antvis/G2


The issue has been closed
【v5】组合图在配置颜色通道时 Tooltip 显示异常 #4997
Deathsteps posted onGitHub
问题描述
双轴,柱线混合,柱配置 encode color 函数后,你 Tooltip 显示异常。
<img width="1154" alt="image" src="https://github.com/antvis/G2/assets/1549118/141fe224-ab8f-48e9-8e87-7796795301f2">
期望结果
- Tooltip 显示 time 字段
- 系列字段应该不显示,或者按 『系列:XXX』这种显示,或其它合理方式
如何重现
官方示例修改
import { Chart } from '@antv/g2';
const data = [
{ time: '10:10', call: 4, waiting: 2, people: 2 },
{ time: '10:15', call: 2, waiting: 6, people: 3 },
{ time: '10:20', call: 13, waiting: 2, people: 5 },
{ time: '10:25', call: 9, waiting: 9, people: 1 },
{ time: '10:30', call: 5, waiting: 2, people: 3 },
{ time: '10:35', call: 8, waiting: 2, people: 1 },
{ time: '10:40', call: 13, waiting: 1, people: 2 },
];
const chart = new Chart({
container: 'container',
theme: 'classic',
autoFit: true,
});
chart.data(data);
chart
.interval()
.encode('x', 'time')
.encode('y', 'waiting')
.encode('color', (d) => d.call > 5 ? 'XXX' : 'YYY')
.axis('y', { title: 'Waiting', style: { titleFill: '#5B8FF9' } })
.tooltip({ channel: 'x', name: 'time' });
chart
.line()
.encode('x', 'time')
.encode('y', 'people')
.encode('shape', 'smooth')
.style('stroke', '#fdae6b')
.style('lineWidth', 2)
.scale('y', { independent: true })
.axis('y', {
position: 'right',
grid: null,
title: 'People',
style: {
titleFill: '#fdae6b',
},
})
.tooltip({ channel: 'x', name: 'time' });
chart.render();
追加 tooltip 项,表现又不一样了,没有 Get 到错乱的根源
.tooltip({ channel: 'x', name: 'time' })
.tooltip({ field: 'call', name: 'call' });
额外信息
G2 5.0.4