Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5] encode color by topN #4674

Closed
coader opened this issue Feb 20, 2023 · 4 comments
Closed

[v5] encode color by topN #4674

coader opened this issue Feb 20, 2023 · 4 comments

Comments

@coader
Copy link

coader commented Feb 20, 2023

image

it's not clear to show TopN, does encode color has callback function to do that?
encode('color', ()=>....)

@pearmini
Copy link
Member

Yes, make sure your data is sorted descending and then encode color as follows:

import { Chart } from '@antv/g2';

const data = [
  { genre: 'Shooter', sold: 350 },
  { genre: 'Sports', sold: 275 },
  { genre: 'Other', sold: 150 },
  { genre: 'Action', sold: 120 },
  { genre: 'Strategy', sold: 115 },
];

const chart = new Chart({
  container: 'container',
});

const TOPN = 2;

chart
  .interval()
  .data(data)
  .encode('x', 'genre')
  .encode('y', 'sold')
  .encode('color', (_, index) => (index > TOPN - 1 ? 'low' : 'high'))
  .scale('color', {
    domain:['high', 'low'],
    range: ['red', 'blue'],
  });

chart.render();

Here is the output:

image

@pearmini
Copy link
Member

Do you use WeChat APP? Maybe we can use it to communicate more efficiently?

@coader
Copy link
Author

coader commented Feb 20, 2023

already send mail to u

@pearmini
Copy link
Member

already send mail to u

OK, I've sent an invitation to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants