antV中柱状图在柱子中间和上方添加文字
在AntV中,您可以使用label配置项在柱子上方或中间添加文字。
- 在柱子中间添加文字:
const data = [
{ year: '2019', sales: 100 },
{ year: '2020', sales: 200 },
{ year: '2021', sales: 300 },
];
const chart = new G2.Chart({
container: 'container',
autoFit: true,
height: 500,
});
chart.data(data);
chart.interval().position('year*sales').label('sales', {
position: 'middle', // 文字显示在柱子中间
style: {
fill: '#fff',
},
});
chart.render();
- 在柱子上方添加文字:
const data = [
{ year: '2019', sales: 100 },
{ year: '2020', sales: 200 },
{ year: '2021', sales: 300 },
];
const chart = new G2.Chart({
container: 'container',
autoFit: true,
height: 500,
});
chart.data(data);
chart.interval().position('year*sales').label('sales', {
position: 'top', // 文字显示在柱子上方
style: {
fill: '#fff',
},
});
chart.render();
您可以通过修改label的配置项来调整文字的样式和位置。更多关于label的用法,请参考AntV官方文档。
原文地址: https://www.cveoy.top/t/topic/bnGQ 著作权归作者所有。请勿转载和采集!