首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Apache POI在PPT上编写折线图

如何使用Apache POI在PPT上编写折线图
EN

Stack Overflow用户
提问于 2016-10-12 10:24:44
回答 1查看 854关注 0票数 0

有没有一个很好的例子来说明如何使用apache POI在PPT上绘制折线图?

我正在使用apache POIs XSLFSlide来生成PPT。我没有看到一个使用XSLFSlide画线的例子。

EN

回答 1

Stack Overflow用户

发布于 2017-08-21 09:53:44

一般而言,此条形图具有相同的概念。只需更改为多行

代码语言:javascript
复制
 public static void main(String[] args) throws Exception {
    HSLFSlideShow ppt = new HSLFSlideShow();

    try {
        //bar chart data. The first value is the bar color, the second is the width
        Object[] def = new Object[]{
            Color.yellow, 40,
            Color.green, 60,
            Color.gray, 30,
            Color.red, 80,
        };

        HSLFSlide slide = ppt.createSlide();

        HSLFGroupShape group = new HSLFGroupShape();
        //define position of the drawing in the slide
        Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
        group.setAnchor(bounds);
        group.setInteriorAnchor(new java.awt.Rectangle(0, 0, 100, 100));
        slide.addShape(group);
        Graphics2D graphics = new PPGraphics2D(group);

        //draw a simple bar graph
        int x = 10, y = 10;
        graphics.setFont(new Font("Arial", Font.BOLD, 10));
        for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
            graphics.setColor(Color.black);
            int width = ((Integer)def[i+1]).intValue();
            graphics.drawString("Q" + idx, x-5, y+10);
            graphics.drawString(width + "%", x + width+3, y + 10);
            graphics.setColor((Color)def[i]);
            graphics.fill(new Rectangle(x, y, width, 10));
            y += 15;
        }
        graphics.setColor(Color.black);
        graphics.setFont(new Font("Arial", Font.BOLD, 14));
        graphics.draw(group.getInteriorAnchor());
        graphics.drawString("Performance", x + 30, y + 10);

        FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
        ppt.write(out);
        out.close();
    } finally {
        ppt.close();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39989545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档