1

When creating a XSLFChart on a XSLFSlide, I can't seem to get the anchoring to work as intended. I'm generate the chart as follows

XSLFSlide slide = ppt.createSlide();
XSLFChart chart = ppt.createChart(slide);
slide.addChart(chart, new Rectangle(200, 200, 200, 200));
// Further styling and data

But when I open the Powerpoint, the chart is scrunched up in the top left corner, as if it was anchored with a Rectangle at (0, 0) with a height and width of 0. Creating the chart with the other overload of the function (addChart(XSLFChart)) also creates it in the corner, but with some height and width.

1 Answers1

1

The position of the XSLFChart needs to be set in measurement unit English Metric Units EMU, not in points as for other anchors of XSLFSimpleShape. There is org.apache.poi.util.Units to convert between different other units (points also) and EMU.

In your case:

XSLFSlide slide = ppt.createSlide();
XSLFChart chart = ppt.createChart(slide);
Rectangle rect = new Rectangle(200*Units.EMU_PER_POINT, 200*Units.EMU_PER_POINT, 200*Units.EMU_PER_POINT, 200*Units.EMU_PER_POINT);
slide.addChart(chart, rect);
Axel Richter
  • 56,077
  • 6
  • 60
  • 87
  • That got it to work. Interesting that charts are so different with the rectangles they expect with no documentation to represent so. – A_Singular_Stick Feb 04 '20 at 16:02