import com.imsl.chart.*; import java.text.DateFormat; import java.util.*; public class SampleCandlestick extends JFrameChart { private double high[], low[], open[], close[]; public SampleCandlestick() { Chart chart = getChart(); AxisXY axis = new AxisXY(chart); // Date is June 27, 1999 Date date = new GregorianCalendar(1999, GregorianCalendar.JUNE, 27).getTime(); int n = 30; createData(n); // Create an instance of a HighLowClose Chart Candlestick stick = new Candlestick(axis, date, high, low, close, open); // Show up days in green and down days in red stick.getUp().setFillColor("green"); stick.getDown().setFillColor("red"); // Set the HighLowClose Chart Title chart.getChartTitle().setTitle("Stock Prices"); // Setup the x axis Axis1D axisX = axis.getAxisX(); // Setup the time axis stick.setDateAxis("Date(SHORT)"); // Turn on grid and make it light gray axisX.getGrid().setPaint(true); axisX.getGrid().setLineColor("lightgray"); axis.getAxisY().getGrid().setPaint(true); axis.getAxisY().getGrid().setLineColor("lightgray"); } private void createData(int n) { high = new double[n]; low = new double[n]; close = new double[n]; open = new double[n]; Random r = new Random(123457); for (int k = 0; k < n; k++) { double f = r.nextDouble(); if (k == 0) { close[0] = 100; } else { close[k] = (0.95+0.10*f)*close[k-1]; } high[k] = close[k]*(1.+0.05*r.nextDouble()); low[k] = close[k]*(1.-0.05*r.nextDouble()); open[k] = low[k] + r.nextDouble()*(high[k]-low[k]); } } public static void main(String argv[]) { new SampleCandlestick().setVisible(true); } }