antvis/G2
The issue has been closed
The label render callback function should return a color #5474
ancyloce posted onGitHub
AntV Open Source Contribution Plan(可选)
- 我同意将这个 Issue 参与 OSCP 计划
Issue 类型
中级任务
任务介绍
给 label 提供第个参数,会返回图形的一些信息,包含图形颜色。使用 label 的颜色可以根据图形属性决定。
import { Chart } from '@antv/g2';
const chart = new Chart({ container: 'container' });
chart
.interval()
.data([
{ genre: 'Sports', sold: 0 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
])
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre')
.style('minHeight', 50)
.label({ text: 'genre', fill: (_, i, array, d) => d.fill }); // label 颜色和图形保持一致
chart.render();