KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > AreaGraphExample


1 import org.faceless.graph2.*;
2 import java.awt.Color JavaDoc;
3 import java.io.FileOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 public class AreaGraphExample
7 {
8     public static void main (String JavaDoc args[]) throws IOException JavaDoc
9     {
10         AxesGraph graph = new AxesGraph();
11     graph.setXRotation(25);
12     graph.setYRotation(15);
13
14         // First we create two FunctionLineSeries objects
15
//
16
FunctionLineSeries sin = new FunctionLineSeries("Sine", 0, 6) {
17         public double func(double x) { return Math.cos(x)+2; }
18     };
19         sin.setStyle(new Style(Color.RED));
20         
21     FunctionLineSeries cos = new FunctionLineSeries("CoSine", 0, 6) {
22         public double func(double x) { return Math.sin(x)+2; }
23     };
24         cos.setStyle(new Style(Color.BLUE));
25         
26         // Then we add them to an AreaSeries and add that to the graph.
27
//
28
AreaSeries series = new AreaSeries("area");
29     series.add(cos);
30     series.add(sin);
31         graph.addSeries(series);
32
33         // Create the key
34
//
35
Key key = new Key(new Style(Color.WHITE));
36     key.addSeries(sin, new TextStyle("Times", 12, Color.BLACK));
37         key.addSeries(cos, new TextStyle("Times", 12, Color.BLACK));
38         graph.addKey(key, Align.RIGHT);
39
40         // Finally we write the graph to a file.
41
//
42
ImageOutput image = new ImageOutput(500,300);
43         graph.draw(image);
44         FileOutputStream JavaDoc out = new FileOutputStream JavaDoc("AreaGraphExample.png");
45     image.writePNG(out, 0);
46         out.close();
47     }
48 }
49
Popular Tags