答案 0 :(得分:1)
您可以在加载/重绘事件上动态重新定位图例项。
根据你的小提琴,方法可以是这样的(对于html项目宽度必须以不同的方式抓取)
function adjustLegend() {
const legend = this.legend
const legendWidth = this.chartWidth - 20
legend.allItems.forEach((item, i, allItems) => {
const {width, height} = item.legendGroup.getBBox()
const itemsPerRow = i < 3 ? 3 : 2
item.legendGroup.attr({
translateX: (i % itemsPerRow) * (legendWidth - width) / (itemsPerRow - 1),
translateY: Math.floor(i / 3) * (height + 5)
})
})
}
在图表选项中:
events: {
load: adjustLegend,
redraw: adjustLegend
}