Chart.js图例对齐左侧

20

CodeSandbox

如何将图例移到左侧?我尝试使用 options:{legend:{position: 'left'}}

目标: enter image description here

position: left 会将图表向右移,这对我来说不好:

enter image description here


选项: { 图例:{ 位置:'左侧' } } 应该可以工作。 - Devsi Odedra
@DevsiOdedra,不行啊,对我没用。我在我的问题中已经写了。 - Arthur
@DevsiOdedra,问题已更新 - Arthur
1
请参见 https://github.com/chartjs/Chart.js/issues/3934 - Devsi Odedra
1
如果我没记错的话,有类似于对齐或者对准的东西,所以尝试使用 {position: 'top', align: 'left'} - Zydnar
@Zydnar,我尝试过了,但对我不起作用。 - Arthur
2个回答

39

你的代码是正确的,将来你将能够像以下一样对齐图例:

legend: {
    position: "top",
    align: "start"
}

但是该功能目前尚未实现(截至2019年3月30日)。该功能已经合并,将在2.9版本中发布。您可以等待2.9版本发布,或使用开发版,但这不是推荐的做法,因为它们只应用于测试目的。


1

文档中建议的那样,使用版本2.9,并使用插件命名空间,例如:

this.piechart = new Chart(this.ctx, {
      type: 'pie',
      data: data,
      options: {
        plugins: {
          legend: {
            position: 'right',
            align: 'center'
          }
        }
      }
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接