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 import java.text.SimpleDateFormat ; 7 import java.text.ParseException ; 8 import java.text.NumberFormat ; 9 10 public class CandleGraphExample 11 { 12 public static void main (String args[]) throws IOException 13 { 14 AxesGraph graph = new AxesGraph(); 17 graph.setAxis(Axis.LEFT, new NumericAxis(NumberFormat.getCurrencyInstance(), Axis.DENSITY_NORMAL)); 18 graph.setAxis(Axis.BOTTOM, new DateAxis()); 19 TextStyle ts = new TextStyle("Default", 10, Color.BLACK); 20 ts.setRotate(-20); 21 ts.setAlign(Align.RIGHT); 22 ts.setPaddingRight(-6); 23 ts.setPaddingTop(-1); 24 graph.getAxis(Axis.BOTTOM).setToothTextStyle(ts); 25 26 SimpleDateFormat df = new SimpleDateFormat ("dd-MMM-yyyy"); 29 CandleSeries candle = new CandleSeries("YHOO"); 30 try { 31 candle.set(df.parse("02-JAN-2002"),18.14,18.63,17.68,18.69); 34 candle.set(df.parse("03-JAN-2002"),18.70,19.13,18.54,19.29); 35 candle.set(df.parse("04-JAN-2002"),19.00,18.90,18.53,19.81); 36 candle.set(df.parse("07-JAN-2002"),18.70,19.73,18.65,19.94); 37 candle.set(df.parse("08-JAN-2002"),19.40,19.53,19.25,19.73); 38 candle.set(df.parse("09-JAN-2002"),19.80,20.25,19.77,21.35); 39 candle.set(df.parse("10-JAN-2002"),20.06,20.49,19.95,20.71); 40 candle.set(df.parse("11-JAN-2002"),20.52,20.16,20.02,20.90); 41 candle.set(df.parse("14-JAN-2002"),19.71,19.01,18.87,19.92); 42 candle.set(df.parse("15-JAN-2002"),19.22,19.47,18.82,19.48); 43 candle.set(df.parse("16-JAN-2002"),18.92,17.87,17.80,19.08); 44 candle.set(df.parse("17-JAN-2002"),19.37,20.12,19.25,20.38); 45 candle.set(df.parse("18-JAN-2002"),19.66,19.20,18.95,19.98); 46 candle.set(df.parse("22-JAN-2002"),19.90,18.42,18.40,20.05); 47 candle.set(df.parse("23-JAN-2002"),18.80,18.44,17.97,18.85); 48 candle.set(df.parse("24-JAN-2002"),18.93,18.19,18.02,19.40); 49 candle.set(df.parse("25-JAN-2002"),18.32,18.68,18.06,18.85); 50 candle.set(df.parse("28-JAN-2002"),18.83,18.70,18.40,18.91); 51 candle.set(df.parse("29-JAN-2002"),18.81,18.18,17.71,18.81); 52 candle.set(df.parse("30-JAN-2002"),18.19,17.19,16.18,18.20); 53 candle.set(df.parse("31-JAN-2002"),17.70,17.24,16.79,17.80); 54 55 candle.setBarWidth(0.8); 58 candle.setStyle(new Style(Color.BLACK)); 59 candle.setStyle(df.parse("23-JAN-2002"), new Style(Color.RED)); 60 61 Marker m = new Marker("star", 14); 64 m.setStyle(new Style(Color.RED)); 65 candle.addMarker(m, DateAxis.toDouble(df.parse("23-JAN-2002")), 17.85); 66 candle.addMarker(new Text("My Birthday", new TextStyle("Default", 10, Color.RED)),DateAxis.toDouble(df.parse("23-JAN-2002")), 17.65); 67 } 68 catch (ParseException e) { 69 e.printStackTrace(); 70 } 71 72 graph.addSeries(candle); 75 graph.setBackWallPaint(null, new Color (204,204,204), Axis.LEFT, Axis.BOTTOM, null); 76 77 graph.addText("January 2002 Yahoo! Inc Stock Prices", new TextStyle("Times", 24, Color.BLUE, Align.CENTER)); 80 81 ImageOutput image = new ImageOutput(500, 500); 84 graph.draw(image); 85 FileOutputStream out = new FileOutputStream ("CandleGraphExample.png"); 86 image.writePNG(out, 0); 87 out.close(); 88 } 89 } | Popular Tags |