User (Legacy) Posted June 29, 2006 Report Share Posted June 29, 2006 Hi How do I get a Chart as image object? You can get it as file or stream it out in a servlet. But why not as a java.awt.Image http://java.sun.com/j2se/1.3/docs/api/java/awt/Image.html Java is a OO language and I see ChartFX as a excellent chart framework, but why cant' I do something like this: public java.awt.Image getImage() on the Chart class? I could be very useful. Right now I am creating PDF's with iText (java pdf framework) http://www.lowagie.com/iText/ <http://www.lowagie.com/iText/ and is trying to put at Chart into it. It supports java.awt.Image. An other example could be adding a chart to an awt application. /TJM Link to comment Share on other sites More sharing options...
Software FX Posted July 3, 2006 Report Share Posted July 3, 2006 There is a paint method that will paint the chart to a Graphics2D object: java.awt.Graphics2D g2d = new java.awt.Graphics2D(); chart1.paint(g2d,0,0,"width","height",SoftwareFX.ChartFX.PaintFlags.BACKGROUND); ...but I don't know if you can convert the Graphics2D to java.awt.Image. The other way to do it is to export the chart to an image, and the the Image from it, somthing like this: java.io.ByteArrayOutputStream image = new java.io.ByteArrayOutputStream(); chart1.exportChart(FileFormat.PNG,image); javax.swing.ImageIcon ico = new javax.swing.ImageIcon(image.toByteArray()); java.awt.Image img = ico.getImage(); GA SoftwareFX, Inc. "TJM" <nospam@nospam.dk> wrote in message news:Rr4HMS8mGHA.2336@webserver3.softwarefx.com... > Hi > > How do I get a Chart as image object? > > You can get it as file or stream it out in a servlet. But why not as a > java.awt.Image http://java.sun.com/j2se/1.3/docs/api/java/awt/Image.html > > Java is a OO language and I see ChartFX as a excellent chart framework, > but why cant' I do something like this: > > public java.awt.Image getImage() on the Chart class? > > I could be very useful. > > Right now I am creating PDF's with iText (java pdf framework) > http://www.lowagie.com/iText/ <http://www.lowagie.com/iText/ and is trying > to put at Chart into it. It supports java.awt.Image. > > An other example could be adding a chart to an awt application. > > /TJM > > > Link to comment Share on other sites More sharing options...
User (Legacy) Posted July 3, 2006 Author Report Share Posted July 3, 2006 HI, iText also support that add Jpeg file to pdf so that you can the following method java.io.ByteArrayOutputStream image = new java.io.ByteArrayOutputStream(); chart1.exportChart(FileFormat.Jpeg,image); document.add(new Jpeg(image.toByteArray())); /SJ "TJM" <nospam@nospam.dk> wrote in message news:Rr4HMS8mGHA.2336@webserver3.softwarefx.com... > Hi > > How do I get a Chart as image object? > > You can get it as file or stream it out in a servlet. But why not as a > java.awt.Image http://java.sun.com/j2se/1.3/docs/api/java/awt/Image.html > > Java is a OO language and I see ChartFX as a excellent chart framework, > but why cant' I do something like this: > > public java.awt.Image getImage() on the Chart class? > > I could be very useful. > > Right now I am creating PDF's with iText (java pdf framework) > http://www.lowagie.com/iText/ <http://www.lowagie.com/iText/ and is trying > to put at Chart into it. It supports java.awt.Image. > > An other example could be adding a chart to an awt application. > > /TJM > > > Link to comment Share on other sites More sharing options...
User (Legacy) Posted July 4, 2006 Author Report Share Posted July 4, 2006 > There is a paint method that will paint the chart to a Graphics2D object: > > java.awt.Graphics2D g2d = new java.awt.Graphics2D(); > chart1.paint(g2d,0,0,"width","height",SoftwareFX.ChartFX.PaintFlags.BACKGROUND); > > ...but I don't know if you can convert the Graphics2D to java.awt.Image. > > The other way to do it is to export the chart to an image, and the the > Image from it, somthing like this: > > java.io.ByteArrayOutputStream image = new java.io.ByteArrayOutputStream(); > chart1.exportChart(FileFormat.PNG,image); > javax.swing.ImageIcon ico = new > javax.swing.ImageIcon(image.toByteArray()); > java.awt.Image img = ico.getImage(); Thanks I got it working using ByteArrayOutputStream and ByteArrayOutputStream.toByteArray() also supported by iText. /TJM Link to comment Share on other sites More sharing options...
User (Legacy) Posted July 4, 2006 Author Report Share Posted July 4, 2006 > There is a paint method that will paint the chart to a Graphics2D object: > > java.awt.Graphics2D g2d = new java.awt.Graphics2D(); > chart1.paint(g2d,0,0,"width","height",SoftwareFX.ChartFX.PaintFlags.BACKGROUND); > > ...but I don't know if you can convert the Graphics2D to java.awt.Image. > > The other way to do it is to export the chart to an image, and the the > Image from it, somthing like this: > > java.io.ByteArrayOutputStream image = new java.io.ByteArrayOutputStream(); > chart1.exportChart(FileFormat.PNG,image); > javax.swing.ImageIcon ico = new > javax.swing.ImageIcon(image.toByteArray()); > java.awt.Image img = ico.getImage(); Thanks I got it working using ByteArrayOutputStream and ByteArrayOutputStream.toByteArray() also supported by iText. /TJM Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.