KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MarkerExample


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 MarkerExample
7 {
8     public static void main(String JavaDoc args[]) throws IOException JavaDoc
9     {
10         // Create a new AxesGraph. Set the bottom axis to a MarkerAxis,
11
// to display the bar keys as markers
12
//
13
AxesGraph graph = new AxesGraph();
14         graph.setAxis(Axis.BOTTOM, new MarkerAxis(20));
15         graph.setXRotation(20);
16         graph.setYRotation(30);
17         
18         // Create a new series and set some values on it
19
//
20
BarSeries series1 = new BarSeries("populations");
21         series1.setStyle(new Style(Color.GREEN));
22         series1.setBarWidth(0.5);
23         series1.setBarDepth(0.8);
24         series1.set("flag.UK", 59778002);
25         series1.set("flag.AU", 19546792);
26         series1.set("flag.NZ", 3908037);
27         series1.set("flag.VE", 24287670);
28         series1.set("flag.FR", 59765983);
29         series1.set("flag.GR", 10645343);
30         series1.set("flag.CA", 31902268);
31         series1.set("flag.EG", 70712345);
32         series1.set("flag.CO", 41008227);
33         series1.set("flag.RU", 144978573);
34         series1.set("flag.DE", 83251851);
35         series1.set("flag.IT", 57715625);
36         series1.set("flag.ZA", 43647658);
37
38     graph.addSeries(series1);
39         
40         // Create a new Key
41
//
42
Style style = new Style(new Color JavaDoc(249, 218, 232));
43         style.setBorderColor(Color.BLACK);
44         style.setLineThickness(2);
45         Key key = new Key(style);
46         
47         // Add our flags to the key.
48
//
49
TextStyle ts = new TextStyle("Comic", 14, Color.BLACK);
50         key.addCustom(new Marker("flag.UK", 15), "United Kingdom", ts);
51         key.addCustom(new Marker("flag.AU", 15), "Australia", ts);
52         key.addCustom(new Marker("flag.NZ", 15), "New Zealand", ts);
53         key.addCustom(new Marker("flag.VE", 15), "Venezuela", ts);
54         key.addCustom(new Marker("flag.FR", 15), "France", ts);
55         key.addCustom(new Marker("flag.GR", 15), "Greece", ts);
56         key.addCustom(new Marker("flag.CA", 15), "Canada", ts);
57         key.addCustom(new Marker("flag.EG", 15), "Egypt", ts);
58         key.addCustom(new Marker("flag.CO", 15), "Colombia", ts);
59         key.addCustom(new Marker("flag.RU", 15), "Russian Federation", ts);
60         key.addCustom(new Marker("flag.DE", 15), "Germany", ts);
61         key.addCustom(new Marker("flag.IT", 15), "Italy", ts);
62         key.addCustom(new Marker("flag.ZA", 15), "South Africa", ts);
63         graph.addKey(key, Align.RIGHT);
64         
65         // Set some labels on the X and Y axes
66
//
67
graph.addText("Populations", new TextStyle("Helvetica", 30, Color.BLUE, Align.CENTER));
68         graph.getAxis(Axis.LEFT).setLabel("Number of People", new TextStyle("Times", 12, Color.BLACK));
69         graph.getAxis(Axis.BOTTOM).setLabel("Country", new TextStyle("Times", 12, Color.BLACK));
70         
71         // And finally, write the image out
72
//
73
ImageOutput image = new ImageOutput(650,500);
74
75         // We used a custom font above, and here's how we'd link that in to a specific
76
// AWT font. Commented out so people on UNIX can run this example
77
//
78
// image.setFont("comic", Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("C:/WINDOWS/Fonts/comic.ttf")));
79

80         graph.draw(image);
81     FileOutputStream JavaDoc out = new FileOutputStream JavaDoc("MarkerExample.png");
82     image.writePNG(out, 0);
83         out.close();
84     }
85 }
86
Popular Tags