心流logo

antv/g2让图表的legend显示在底部、

在使用 AntV/G2 绘制图表时,如果你希望将图例(legend)显示在图表的底部,可以通过配置 legendposition 属性来实现。以下是具体的方法:

示例代码

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();

说明

其他可选位置

除了 'bottom'position 还支持以下值: