当添加一个图例时, 可以保持以前的图例颜色不变吗? #5008
Answered
by
hustcc
vaynevayne
asked this question in
Q&A
-
5-11 号的颜色变了 ![]() ![]() 有办法做到吗? 比如说固定图例的顺序 |
Beta Was this translation helpful? Give feedback.
Answered by
hustcc
May 12, 2023
Replies: 2 comments 1 reply
-
可以的,对颜色通道进行回调即可,对于 G2 v4 版本,使用: chart
.line()
.position('month*temperature')
.color('city', (city) => city === 'London' ? 'red' : 'blue'); // 👈🏻 对于 v5 版本,可以使用: chart
.line()
.encode('x', (d) => new Date(d.Date))
.encode('y', 'Close')
.encode('color', 'Symbol')
.scale('color', {
relations: [['AAPL', '#ff0000']], // 👈🏻
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hustcc
-
找到个简单的办法, 事先unshift一条有type,但没值的数据到data里, 这样有图例没数据, 颜色就不会变了 data.unshift({type:'参考值'}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以的,对颜色通道进行回调即可,对于 G2 v4 版本,使用:
对于 v5 版本,可以使用: