A_Singular_Stick
A_Singular_Stick

Reputation: 15

Resizing a XSLFChart

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.

Upvotes: 1

Views: 267

Answers (1)

Axel Richter
Axel Richter

Reputation: 61852

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);

Upvotes: 1

Related Questions