Skip to content

当添加一个图例时, 可以保持以前的图例颜色不变吗? #5008

Answered by hustcc
vaynevayne asked this question in Q&A
Discussion options

You must be logged in to vote

可以的,对颜色通道进行回调即可,对于 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']],  // 👈🏻
  })                          

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by hustcc
Comment options

You must be logged in to vote
1 reply
@hustcc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #5007 on May 12, 2023 00:59.