In an HTML-client application, the thin graph produces a GIF that is rendered into an HTML page. In a Java-client application or applet, you can produce an image file from a graph. You can create a GIF, a JPEG, or a PNG file from a Java-client graph.
To create a GIF image, you call the exportToGIF
method of the graph.
To create a JPEG image, you call the exportToJPEG
method of the graph.
To create a PNG image, you call the exportToPNG
method of the graph.
To set the resolution for the image, call the setImageSize
method
of the graph before you call the method to create the image. You can also specify
whether to have font sizes scaled for the image size, by calling setScaleFontSizeForGIF
.
The following short example shows how to create a GIF file from the default graph. This
example creates a GIF file called myThinGraph.gif
in the current folder.
Graph myThickGraph = new Graph(); FileOutputStream filestream = null; try{ filestream = new FileOutputStream("myThinGraph.gif"); } catch(FileNotFoundException e){ // handle the exception here } if(filestream != null){ myThickGraph.exportToGif(filestream); }