G2Plot 图例大小调整 - 如何设置图例宽度和高度
要将 G2Plot 图例变大,请使用图例配置中的 legend: {position: 'right', size: [width, height]} 属性。其中,size 属性用于设置图例的大小,以像素为单位。
例如,要将图例的宽度设置为 200 像素,高度设置为 400 像素,请使用以下代码:
import { Line } from '@antv/g2plot';
const data = [
{ year: '1991', value: 3 },
{ year: '1992', value: 4 },
{ year: '1993', value: 3.5 },
{ year: '1994', value: 5 },
{ year: '1995', value: 4.9 },
{ year: '1996', value: 6 },
{ year: '1997', value: 7 },
{ year: '1998', value: 9 },
{ year: '1999', value: 13 }
];
const linePlot = new Line('container', {
data,
xField: 'year',
yField: 'value',
legend: {
position: 'right',
size: [200, 400]
}
});
linePlot.render();
注意,上述代码中的 'container' 是要将图表渲染到的 DOM 元素的 ID。您需要在 HTML 中创建一个具有该 ID 的元素。
原文地址: https://www.cveoy.top/t/topic/mUeD 著作权归作者所有。请勿转载和采集!