在使用 AntV/G2 绘制图表时,如果你希望将图例(legend)显示在图表的底部,可以通过配置 legend 的 position 属性来实现。以下是具体的方法:
import { Chart } from '@antv/g2';
const chart = new Chart({
container: 'container',
autoFit: true,
height: 500,
});
chart
.interval()
.position('x*y')
.color('type');
// ��
�
�
�
�
�
�
chart.legend({
position: 'bottom', // 设置图例位置为底部
// 可选配置:调整图例样式
itemWidth: 120, // 图例项宽度
itemHeight: 14, // 图例项高度
itemName: {
style: {
fontSize: 12,
},
},
});
chart.data([
{ type: 'A', x: 1, y: 20 },
{ type: 'B', x: 2, y: 32 },
{ type: 'C', x: 3, y: 18 },
{ type: 'D', x: 4, y: 34 },
]);
chart.render();
position: 'bottom':将图例位置设置为底部。除了 'bottom',position 还支持以下值:
'top':图例在顶部。'left':图例在左侧。'right':图例在右侧。'top-left':图例在左上角。'top-right':图例在右上角。'bottom-left':图例在左下角。'bottom-right':图例在右下角。
通过这些配置,你可以灵活地控制图例的位置