Search in sources :

Example 1 with PPGraphics2D

use of org.apache.poi.hslf.model.PPGraphics2D in project activityinfo by bedatadriven.

the class PPTChartRenderer method render.

public void render(PivotChartReportElement element, SlideShow ppt) throws IOException {
    // add first slide
    Slide slide = ppt.createSlide();
    // define position of the drawing in the slide
    Dimension pageSize = ppt.getPageSize();
    Dimension chartSize = new Dimension((int) (pageSize.getWidth() - 72), (int) (pageSize.getHeight() - 183));
    Rectangle bounds = new com.google.code.appengine.awt.Rectangle(new Point(36, 126), chartSize);
    ShapeGroup group = new ShapeGroup();
    group.setAnchor(bounds);
    slide.addShape(group);
    Graphics2D graphics = new PPGraphics2D(group);
    ChartRendererJC jc = new ChartRendererJC();
    jc.render(element, false, graphics, (int) chartSize.getWidth(), (int) chartSize.getHeight(), 72);
}
Also used : PPGraphics2D(org.apache.poi.hslf.model.PPGraphics2D) ChartRendererJC(org.activityinfo.server.report.renderer.ChartRendererJC) Slide(org.apache.poi.hslf.model.Slide) Rectangle(com.google.code.appengine.awt.Rectangle) Dimension(com.google.code.appengine.awt.Dimension) Point(com.google.code.appengine.awt.Point) ShapeGroup(org.apache.poi.hslf.model.ShapeGroup) PPGraphics2D(org.apache.poi.hslf.model.PPGraphics2D) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Example 2 with PPGraphics2D

use of org.apache.poi.hslf.model.PPGraphics2D in project poi by apache.

the class Graphics2DDemo method main.

/**
     * A simple bar chart demo
     */
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();
    }
}
Also used : Rectangle(java.awt.Rectangle) Rectangle(java.awt.Rectangle) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Font(java.awt.Font) PPGraphics2D(org.apache.poi.hslf.model.PPGraphics2D) Graphics2D(java.awt.Graphics2D) PPGraphics2D(org.apache.poi.hslf.model.PPGraphics2D) HSLFGroupShape(org.apache.poi.hslf.usermodel.HSLFGroupShape) FileOutputStream(java.io.FileOutputStream) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide)

Aggregations

PPGraphics2D (org.apache.poi.hslf.model.PPGraphics2D)2 Dimension (com.google.code.appengine.awt.Dimension)1 Graphics2D (com.google.code.appengine.awt.Graphics2D)1 Point (com.google.code.appengine.awt.Point)1 Rectangle (com.google.code.appengine.awt.Rectangle)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 FileOutputStream (java.io.FileOutputStream)1 ChartRendererJC (org.activityinfo.server.report.renderer.ChartRendererJC)1 ShapeGroup (org.apache.poi.hslf.model.ShapeGroup)1 Slide (org.apache.poi.hslf.model.Slide)1 HSLFGroupShape (org.apache.poi.hslf.usermodel.HSLFGroupShape)1 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)1 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)1