简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM