Geração de Gráficos utilizando POI

1 resposta
Metaleiro

[color=darkblue]Alguém já utilizou o POI para geração de gráficos do Excel, caso alguém já tenha utilizado e puder postar um exemplo ficaria agradecido. [/color]

1 Resposta

Metaleiro

[color=darkblue] Bem atá agora isso foi o que consegui, tenho que dar uma melhorada ainda, achei um código na net e o restante utilizando a documentação do POI, se alguém puder ajudar agradeço
[/color]

HSSFRow rowGra = sheetGra.createRow((short)2);
        rowGra.setHeight((short) 2800);
        sheetGra.setColumnWidth((short) 2, (short) 9000);
        
        HSSFPatriarch graphic = sheetGra.createDrawingPatriarch();
        drawLinesToCenter( graphic );
        drawManyLines( graphic );
        drawOval( graphic );
        drawPolygon( graphic );
        
        HSSFSimpleShape rect = graphic.createSimpleShape( new HSSFClientAnchor(100, 100, 900, 200, (short)0, 0, (short)0, 0) );
        rect.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
        
        /*HSSFClientAnchor anchor = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
        HSSFSimpleShape shape1 = graphic.createSimpleShape(anchor);
        shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);*/
        
        HSSFTextbox textbox1 = graphic.createTextbox(
        new HSSFClientAnchor(0,0,0,0,(short)1,1,(short)2,2));
        textbox1.setString(new HSSFRichTextString("Isto é um teste") );
        
        /*HSSFSimpleShape s = graphic.createSimpleShape(anchor);
        s.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
        s.setLineStyleColor(10,10,10);
        s.setFillColor(90,10,200);
        s.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT * 3);
        s.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);*/


 private static void drawPolygon( HSSFPatriarch patriarch )
     {
         //        HSSFClientAnchor a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 2, 2, (short) 3, 3 );
         //        HSSFPolygon p = patriarch.createPolygon(a);
         //        p.setPolygonDrawArea(100,100);
         //        p.setPoints( new int[]{30, 90, 50}, new int[]{88, 5, 44} );


         HSSFClientAnchor a = new HSSFClientAnchor();
         a.setAnchor( (short) 2, 2, 0, 0, (short) 3, 3, 1023, 255 );
         HSSFShapeGroup g = patriarch.createGroup( a );
         g.setCoordinates(0,0,200,200);
         HSSFPolygon p1 = g.createPolygon( new HSSFChildAnchor( 0, 0, 200, 200 ) );
         p1.setPolygonDrawArea( 100, 100 );
         p1.setPoints( new int[]{0, 90, 50}, new int[]{5, 5, 44} );
         p1.setFillColor( 0, 255, 0 );
         HSSFPolygon p2 = g.createPolygon( new HSSFChildAnchor( 20, 20, 200, 200 ) );
         p2.setPolygonDrawArea( 200, 200 );
         p2.setPoints( new int[]{120, 20, 150}, new int[]{105, 30, 195} );
         p2.setFillColor( 255, 0, 0 );
     }

     private static void drawManyLines( HSSFPatriarch patriarch )
     {
         // Draw bunch of lines
         int x1 = 100;
         int y1 = 100;
         int x2 = 800;
         int y2 = 200;
         int color = 0;
         for (int i = 0; i < 10; i++)
         {
             HSSFClientAnchor a2 = new HSSFClientAnchor();
             a2.setAnchor((short) 2, 2, x1, y1, (short) 2, 2, x2, y2);
             HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
             shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
             shape2.setLineStyleColor(color);
             y1 -= 10;
             y2 -= 10;
             color += 30;
         }
     }

     private static void drawGrid( HSSFPatriarch patriarch )
     {
         // This draws a grid of lines.  Since the coordinates space fixed at
         // 1024 by 256 we use a ratio to get a reasonably square grids.

         double xRatio = 3.22;
         double yRatio = 0.6711;

         int x1 = 000;
         int y1 = 000;
         int x2 = 000;
         int y2 = 200;
         for (int i = 0; i < 20; i++)
         {
             HSSFClientAnchor a2 = new HSSFClientAnchor();
             a2.setAnchor((short) 2, 2, (int) ( x1 * xRatio ), (int) ( y1 * yRatio ),
                     (short) 2, 2, (int) ( x2 * xRatio ), (int) ( y2 * yRatio ));
             HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
             shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);

             x1 += 10;
             x2 += 10;
         }

         x1 = 000;
         y1 = 000;
         x2 = 200;
         y2 = 000;
         for (int i = 0; i < 20; i++)
         {
             HSSFClientAnchor a2 = new HSSFClientAnchor();
             a2.setAnchor((short) 2, 2, (int) ( x1 * xRatio ), (int) ( y1 * yRatio ),
                     (short) 2, 2, (int) ( x2 * xRatio ), (int) ( y2 * yRatio ));
             HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
             shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);

             y1 += 10;
             y2 += 10;
         }
     }

     private static void drawLinesToCenter( HSSFPatriarch patriarch )
     {
         // Draw some lines from and to the corners
         {
             HSSFClientAnchor a1 = new HSSFClientAnchor();
             a1.setAnchor( (short)2, 2, 0, 0, (short) 2, 2, 512, 128 );
             HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1);
             shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
         }
         {
             HSSFClientAnchor a1 = new HSSFClientAnchor();
             a1.setAnchor( (short)2, 2, 512, 128, (short) 2, 2, 1024, 0);
             HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1);
             shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
         }
         {
             HSSFClientAnchor a1 = new HSSFClientAnchor();
             a1.setAnchor( (short)1, 1, 0, 0, (short) 1, 1, 512, 100);
             HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1);
             shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
         }
         {
             HSSFClientAnchor a1 = new HSSFClientAnchor();
             a1.setAnchor( (short)1, 1, 512, 100, (short) 1, 1, 1024, 0);
             HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1);
             shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
         }

     }
Criado 2 de outubro de 2006
Ultima resposta 3 de out. de 2006
Respostas 1
Participantes 1