antv g2plot中的玫瑰图添加蜘蛛布局标签
在 antv G2Plot 中,可以通过设置 label 属性来添加蜘蛛布局标签。具体步骤如下:
- 在创建玫瑰图时,设置
coordinate属性为polar,并设置isTransposed为true,使得玫瑰图变为蜘蛛布局。
const plot = new G2Plot.RosePlot({
data,
angleField: 'type',
radiusField: 'value',
coordinate: {
type: 'polar',
isTransposed: true,
},
...
});
- 在
label属性中设置layout为spider,并设置content属性为标签文本值所对应的字段名。
const plot = new G2Plot.RosePlot({
data,
angleField: 'type',
radiusField: 'value',
coordinate: {
type: 'polar',
isTransposed: true,
},
label: {
layout: {
type: 'spider',
},
content: 'value',
...
},
...
});
- 可以进一步设置
label属性中的其他属性,如style,offset,adjustColor等,以符合具体需求。
完整代码示例:
const data = [
{ type: '分类一', value: 27 },
{ type: '分类二', value: 25 },
{ type: '分类三', value: 18 },
{ type: '分类四', value: 15 },
{ type: '分类五', value: 10 },
{ type: '分类六', value: 5 },
];
const plot = new G2Plot.RosePlot({
data,
angleField: 'type',
radiusField: 'value',
coordinate: {
type: 'polar',
isTransposed: true,
},
label: {
layout: {
type: 'spider',
},
content: 'value',
style: {
fontSize: 12,
textAlign: 'center',
},
adjustColor: true,
},
});
plot.render();
原文地址: http://www.cveoy.top/t/topic/E0v 著作权归作者所有。请勿转载和采集!