1 import org.faceless.graph2.*; 2 import java.awt.Color ; 3 import java.awt.Paint ; 4 import java.io.FileOutputStream ; 5 import java.io.IOException ; 6 7 public class PieGraphExample 8 { 9 public static void main (String args[]) throws IOException 10 { 11 Color chocolateFactory = new Color (72,201,47); 13 Color weddingCrashers = new Color (251,163,49); 14 Color fantasticFour = new Color (250,123,213); 15 Color island = Color.CYAN; 16 Color badNewBears = Color.YELLOW; 17 Color warWorlds = new Color (188,129,226); 18 Color hustleFlow = new Color (252,47,110); 19 Color devilsRejects = new Color (250,206,73); 20 Color batmanBegins = new Color (124,124,255); 21 Color marchPenguins = Color.LIGHT_GRAY; 22 23 PieGraph graph = new PieGraph(); 26 graph.set("Charlie and the Chocolate Factory", 28.3); 27 graph.set("Wedding Crashers", 26.2); 28 graph.set("Fantastic Four", 12.3); 29 graph.set("The Island", 12.1); 30 graph.set("The Bad News Bears", 11.5); 31 graph.set("War of the Worlds", 8.8); 32 graph.set("Hustle and Flow", 8.1); 33 graph.set("The Devil's Rejects", 7); 34 graph.set("Batman Begins", 4.7); 35 graph.set("March of the Penguins", 4.3); 36 37 TextStyle labelstyle = new TextStyle("Default",10,Color.BLACK); 40 graph.setLabel ("Charlie and the Chocolate Factory", new Text("$28.5M", labelstyle), 0.9); 41 graph.setLabel ("Wedding Crashers", new Text("$26.2M", labelstyle), 0.9); 42 graph.setLabel ("Fantastic Four", new Text("$12.3M", labelstyle), 0.9); 43 graph.setLabel ("The Island", new Text("$12.1M", labelstyle), 0.9); 44 graph.setLabel ("The Bad News Bears", new Text("$11.5M", labelstyle), 0.9); 45 graph.setLabel ("War of the Worlds", new Text("$8.8M", labelstyle), 0.9); 46 graph.setLabel ("Hustle and Flow", new Text("$8.1M", labelstyle), 0.9); 47 graph.setLabel ("The Devil's Rejects", new Text("$7M", labelstyle), 0.9); 48 graph.setLabel ("Batman Begins", new Text("$4.7M", labelstyle), 0.9); 49 graph.setLabel ("March of the Penguins", new Text("$4.3M", labelstyle), 0.9); 50 51 graph.setDefaultColors(new Paint [] {chocolateFactory,weddingCrashers,fantasticFour,island,badNewBears,warWorlds,hustleFlow,devilsRejects,batmanBegins,marchPenguins}); 54 graph.setYRotation(-30); 55 graph.setZRotation(-10); 56 graph.setDepth(30); 57 58 graph.addText("Weekend Box Office Figures 22-24 July, 2005", new TextStyle("Default", 22, Color.red, Align.CENTER)); 61 graph.addText("North American Theatres", new TextStyle("Default", 18, Color.black, Align.CENTER)); 62 63 Key key = new Key(new Style(Color.WHITE)); 66 TextStyle ts = new TextStyle("Arial", 12, Color.BLACK); 67 Marker m1 = new Marker("square",12); 68 m1.setStyle (new Style(chocolateFactory)); 69 key.addCustom(m1, "Charlie and the Chocolate Factory", ts); 70 Marker m2 = new Marker("square",12); 71 m2.setStyle (new Style(weddingCrashers)); 72 key.addCustom(m2, "Wedding Crashers", ts); 73 Marker m3 = new Marker("square",12); 74 m3.setStyle (new Style(fantasticFour)); 75 key.addCustom(m3, "Fantastic Four", ts); 76 Marker m4 = new Marker("square",12); 77 m4.setStyle (new Style(island)); 78 key.addCustom(m4, "The Island", ts); 79 Marker m5 = new Marker("square",12); 80 m5.setStyle (new Style(badNewBears)); 81 key.addCustom(m5, "The Bad News Bears", ts); 82 Marker m6 = new Marker("square",12); 83 m6.setStyle (new Style(warWorlds)); 84 key.addCustom(m6, "War of the Worlds", ts); 85 Marker m7 = new Marker("square",12); 86 m7.setStyle (new Style(hustleFlow)); 87 key.addCustom(m7, "Hustle and Flow", ts); 88 Marker m8 = new Marker("square",12); 89 m8.setStyle (new Style(devilsRejects)); 90 key.addCustom(m8, "The Devil's Rejects", ts); 91 Marker m9 = new Marker("square",12); 92 m9.setStyle (new Style(batmanBegins)); 93 key.addCustom(m9, "Batman Begins", ts); 94 Marker m10 = new Marker("square",12); 95 m10.setStyle (new Style(marchPenguins)); 96 key.addCustom(m10, "March of the Penguins", ts); 97 key.setMaxWidth(500); 98 graph.addKey(key, Align.BOTTOM); 99 100 ImageOutput image = new ImageOutput(500, 500); 103 graph.draw(image); 104 FileOutputStream out = new FileOutputStream ("PieGraphExample.png"); 105 image.writePNG(out, 0); 106 out.close(); 107 } 108 } | Popular Tags |