antV中柱状图在柱子中间和上方一起显示文字
在antV中柱状图中,在柱子中间和上方一起显示文字需要使用label配置项。具体实现步骤如下:
- 在图表中添加label配置项,设置label的样式和位置。如下所示:
const chart = new Chart({
container: 'container',
autoFit: true,
height: 500,
});
chart.data(data);
chart.scale({
sales: {
max: 5000,
min: 0,
},
});
chart.axis('city', {
label: {
offset: 12, // 设置label距离坐标轴的偏移量
style: {
fontSize: 14,
},
},
});
chart.axis('sales', {
label: {
style: {
fontSize: 14,
},
},
});
chart.coordinate().transpose();
chart.interval().position('city*sales').color('category')
.label('sales', {
style: {
fill: '#fff',
},
position: 'middle', // 在柱子中间显示label
offset: 0, // 设置偏移量
})
.label('sales', {
style: {
fill: '#000',
},
position: 'top', // 在柱子顶部显示label
});
chart.render();
- 在interval上添加两次label,分别设置位置为middle和top,来实现在柱子中间和上方一起显示文字的效果。
通过上述代码实现,在antV中柱状图中,在柱子中间和上方一起显示文字。
原文地址: https://www.cveoy.top/t/topic/bnQQ 著作权归作者所有。请勿转载和采集!