KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MultibarExample


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 MultibarExample
7 {
8     public static void main (String JavaDoc args[]) throws IOException JavaDoc
9     {
10         // Create all the bar series
11
//
12
BarSeries january = new BarSeries("January");
13         january.setBarWidth(0.8);
14     january.set("2001",18);
15     january.set("2002",12);
16     january.set("2003",19);
17     january.set("2004",10);
18         
19         BarSeries february = new BarSeries("February");
20         february.setBarWidth(0.8);
21     february.set("2001",25);
22     february.set("2002",17);
23     february.set("2003",15);
24     february.set("2004",15);
25         
26         BarSeries march = new BarSeries("March");
27         march.setBarWidth(0.8);
28     march.set("2001",21);
29     march.set("2002",12);
30     march.set("2003",17);
31     march.set("2004",4);
32         
33         BarSeries april = new BarSeries("April");
34         april.setBarWidth(0.8);
35     april.set("2001",10);
36     april.set("2002",6);
37     april.set("2003",9);
38     april.set("2004",11);
39         
40         BarSeries may = new BarSeries("May");
41         may.setBarWidth(0.8);
42     may.set("2001",24);
43     may.set("2002",23);
44     may.set("2003",12);
45     may.set("2004",18);
46
47         BarSeries june = new BarSeries("June");
48         june.setBarWidth(0.8);
49     june.set("2001",40);
50     june.set("2002",34);
51     june.set("2003",18);
52     june.set("2004",25);
53         
54         BarSeries july = new BarSeries("July");
55         july.setBarWidth(0.8);
56     july.set("2001",16);
57     july.set("2002",15);
58     july.set("2003",11);
59     july.set("2004",23);
60
61         BarSeries august = new BarSeries("August");
62         august.setBarWidth(0.8);
63     august.set("2001",10);
64     august.set("2002",5);
65     august.set("2003",10);
66     august.set("2004",1);
67
68         BarSeries september = new BarSeries("September");
69         september.setBarWidth(0.8);
70     september.set("2001",16);
71     september.set("2002",25);
72     september.set("2003",30);
73     september.set("2004",21);
74         
75         BarSeries october = new BarSeries("October");
76         october.setBarWidth(0.8);
77     october.set("2001",35);
78     october.set("2002",23);
79     october.set("2003",21);
80     october.set("2004",19);
81
82         BarSeries november = new BarSeries("November");
83         november.setBarWidth(0.8);
84     november.set("2001",12);
85     november.set("2002",25);
86     november.set("2003",22);
87     november.set("2004",10);
88
89         BarSeries december = new BarSeries("December");
90         december.setBarWidth(0.8);
91     december.set("2001",15);
92     december.set("2002",25);
93     december.set("2003",20);
94     december.set("2004",12);
95         
96         // Create a MultibarSeries and add all the series to it
97
//
98
MultiBarSeries mbs = new MultiBarSeries("years");
99         mbs.add(january);
100         mbs.add(february);
101         mbs.add(march);
102         mbs.add(april);
103         mbs.add(may);
104         mbs.add(june);
105         mbs.add(july);
106         mbs.add(august);
107         mbs.add(september);
108         mbs.add(october);
109         mbs.add(november);
110         mbs.add(december);
111
112         // Create the graph and add the MultiBarSeries
113
//
114
AxesGraph graph = new AxesGraph();
115     graph.addSeries(mbs);
116         graph.setBackWallPaint (null, Color.BLACK, Axis.BOTTOM, 0, null);
117         
118         // Create a key and add it to the graph
119
//
120
Style style = new Style(Color.WHITE);
121         style.setBorderColor(Color.WHITE);
122         Key key = new Key(style);
123         graph.addKey(key, Align.TOP);
124
125         // Write the file
126
//
127
ImageOutput image = new ImageOutput(400, 400);
128     graph.draw(image);
129     FileOutputStream JavaDoc out = new FileOutputStream JavaDoc("MultibarExample.png");
130     image.writePNG(out, 0);
131         out.close();
132     }
133 }
Popular Tags