使用JQPlot,我如何将图例放置在图表外部的特定位置?

3

我使用以下代码成功地将图例放在了我的JQPlot折线图外面:

legend: {
   show: true,
   location: 'sw',
   placement: 'outside'
},

然而,这将使图例与我的y轴标签在同一行中过于接近。我需要将其进一步向左移动。有没有方法可以实现这个需求?

参考这篇帖子,我已经发布了答案。is-it-possible-to-write-legend-to-a-separate-division-with-jqplot - Gyandeep
这里是答案,也许其他开发者需要。https://dev59.com/8m3Xa4cB1Zd3GeqPf4kO#20047827 - burakerk
3个回答

6
有点晚了,但我懂了! 你应该使用placement: 'outsideGrid'而不是placement: 'outside',因为'outsideGrid'会缩小图表区域,使图例不会与其混在一起。

4

查看 图例(Legend) 的 marginTop,marginRight,marginBottom 和 marginLeft 属性。

你可以这样做:

legend: { 
    show: true, 
    location: 'sw', 
    placement: 'outside',
    marginLeft: 300
}

1
我尝试使用marginLeft的解决方案,但没有成功。我分别尝试了marginLeft、marginRight、marginTop和marginBottom这4种方法,但都不能移动图例。是否还需要其他设置?我还没有尝试@Gyandeep提供的解决方案,但如果这个简单的方法不能满足我的需求,我会去尝试那个方案。感谢大家。 - Shane Geist

1
你需要像这样使用它:marginLeft: "300px"
legend: { 
    show: true, 
    location: 'sw', 
    placement: 'outside',
    marginLeft: "300px"
}

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