[英]Can you set a specific X, Y position for CTLegend
我正在使用apache POI和OpenOffice库来创建条形图和折线图。 我可以使组合条形图和折线图正常工作,并创建一个漂亮的图例。 但是我想使用STLegendPos的枚举值(.L,.B,.R,.T,.TR)之外的其他东西来定位它。 我正在生成的电子表格包含很多带有图表的工作表,图例覆盖了Y轴。 我将addNewOverlay()设置为true,因为我需要它在图表的顶部,但是我只想以编程方式将其向右移一点,而无需用户进入并移动大约70个图例。
我添加图表图例的代码如下:
private static void addChartLegend(CTChart ctChart) {
// Define legends for the chart and set the position of the legend
CTLegend ctLegend = ctChart.addNewLegend();
ctLegend.addNewLegendPos().setVal(STLegendPos.L);
// Set border color
ctLegend.addNewSpPr().addNewLn().addNewSolidFill().addNewSrgbClr().setVal(new byte[]{(byte)0, (byte)0, (byte)0});
// Set fill color
ctLegend.getSpPr().addNewSolidFill().addNewSrgbClr().setVal(new byte[]{(byte)255, (byte)255, (byte)255});
ctLegend.addNewOverlay().setVal(true); // true overlays it on top of chart; false creates it's own space
}
我进行了很多搜索,试图找到一个没有运气的确切位置设置示例。
感谢您提供的任何帮助。 杰夫
如果你有CTLegend
已经,那么你可以申请一个CTLayout
使用CTLegend.addNewLayout 。 然后, CTManualLayout
必须使用应用CTLayout.addNewManualLayout 。 然后,在CTManualLayout中 ,必须设置CTLayoutMode
的XMode
和YMode
,然后再设置X
和Y
的双YMode
值。
主要问题是获取信息XMode
和YMode
以及X
和Y
的含义。 为此请参见https://msdn.microsoft.com/zh-cn/library/ff534056(v=office.12).aspx :
“对于xMode / yMode元素, edge属性指定同级元素x / y的值解释为从图表的左/上边缘到图表元素的左/上边缘的距离,以图表的百分比表示宽度/高度。”
代码示例:
//legend
CTLegend ctLegend = ctChart.addNewLegend();
ctLegend.addNewLegendPos().setVal(STLegendPos.L);
ctLegend.addNewOverlay().setVal(false);
CTManualLayout ctManualLayout = ctLegend.addNewLayout().addNewManualLayout();
ctManualLayout.addNewXMode().setVal(STLayoutMode.EDGE);
ctManualLayout.addNewYMode().setVal(STLayoutMode.EDGE);
ctManualLayout.addNewX().setVal(0.00); //left edge of the chart
ctManualLayout.addNewY().setVal(0.25); //25% of chart's height from top edge of the chart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.