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
Comments
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: |
Do you use WeChat APP? Maybe we can use it to communicate more efficiently? |
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
it's not clear to show TopN, does encode color has callback function to do that?
encode('color', ()=>....)
The text was updated successfully, but these errors were encountered: