1.图例自定义后内容很长,与图表重合了,可以调整图表的padding
let chart = new G2.Chart({
container: options.ele,
forceFit: true,
height: options.height,
padding: [ 10, 200, 10, 10 ]
})
chart.legend({
position: 'right-center',
useHtml: true,
itemGap: 20, // 图例项之间的间距
itemTpl: (value, color, checked, index) => {
return '<tr class="g2-legend-list-item item-' + index +
'" data-value="' + value + '" data-color=' + color +
' style="cursor: pointer;font-size: 14px;">' +
'<td width=150 style="border: none;padding:0;"><i class="g2-legend-marker" style="width:10px;height:10px;display:inline-block;margin-right:10px;background-color:' + color + ';"></i>' +
'<span class="g2-legend-text">' + value + '</span></td>' +
'<td style="text-align: right;border: none;padding:0;">' + chart._attrs.data[index].value + '</td>' +
'</tr>'
}
})
2:如果卡片添加了loading效果,并且导致挂载后如果loading没有结束,G2将找不到容器报错