对于多个 y 轴,刻度数量级不同,绘制辅助线,起始位置基准是 y 主轴 #4952
Answered
by
hustcc
Song-yi-Tao
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
hustcc
May 16, 2023
Replies: 2 comments
-
非常感谢反馈,我也试了一下,这个问题在 4.x 中确实不是很好实现,我们在 5.x 中考虑进去。 |
Beta Was this translation helpful? Give feedback.
0 replies
-
在 G2 5.0 中可以很好的处理这个问题。下面代码复制到这里运行。 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')
.scale('y', { key: 'left-y' }) // 👈🏻
.axis('y', { title: 'Waiting', style: { titleFill: '#5B8FF9' } });
chart
.lineY()
.data([5])
.style('stroke', '#5B8FF9')
.style('arrow', true)
.scale('y', { key: 'left-y' }) // 👈🏻
chart
.line()
.encode('x', 'time')
.encode('y', 'people')
.encode('shape', 'smooth')
.style('stroke', '#fdae6b')
.style('lineWidth', 2)
.scale('y', { key: 'right-y' }) // 👈🏻
.axis('y', {
position: 'right',
grid: null,
title: 'People',
style: {
titleFill: '#fdae6b',
},
});
chart
.lineY()
.data([2.5])
.style('stroke', '#fdae6b')
.style('arrow', true)
.scale('y', { key: 'right-y' }) // 👈🏻
chart.render(); 只需要 scale 的 key 相同,那么他们的基准就是相同的。 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hustcc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在 G2 5.0 中可以很好的处理这个问题。下面代码复制到这里运行。