public Chart(String title, String timeAxis, String valueAxis, TimeSeries data) { try { // Build the datasets dataset.addSeries(data); // Create the chart JFreeChart chart = ChartFactory.createTimeSeriesChart( title, timeAxis, valueAxis, dataset, true, true, false); // Setup the appearance of the chart chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // Tell the chart how we would like dates to read DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("EEE HH")); this.add(new ChartPanel(chart)); } catch (Exception e) { e.printStackTrace(); } }
public Chart(String filename) { try { // Get Stock Symbol this.stockSymbol = filename.substring(0, filename.indexOf('.')); // Create time series TimeSeries open = new TimeSeries("Open Price", Day.class); TimeSeries close = new TimeSeries("Close Price", Day.class); TimeSeries high = new TimeSeries("High", Day.class); TimeSeries low = new TimeSeries("Low", Day.class); TimeSeries volume = new TimeSeries("Volume", Day.class); BufferedReader br = new BufferedReader(new FileReader(filename)); String key = br.readLine(); String line = br.readLine(); while (line != null && !line.startsWith("<!--")) { StringTokenizer st = new StringTokenizer(line, ",", false); Day day = getDay(st.nextToken()); double openValue = Double.parseDouble(st.nextToken()); double highValue = Double.parseDouble(st.nextToken()); double lowValue = Double.parseDouble(st.nextToken()); double closeValue = Double.parseDouble(st.nextToken()); long volumeValue = Long.parseLong(st.nextToken()); // Add this value to our series' open.add(day, openValue); close.add(day, closeValue); high.add(day, highValue); low.add(day, lowValue); // Read the next day line = br.readLine(); } // Build the datasets dataset.addSeries(open); dataset.addSeries(close); dataset.addSeries(low); dataset.addSeries(high); datasetOpenClose.addSeries(open); datasetOpenClose.addSeries(close); datasetHighLow.addSeries(high); datasetHighLow.addSeries(low); JFreeChart summaryChart = buildChart(dataset, "Summary", true); JFreeChart openCloseChart = buildChart(datasetOpenClose, "Open/Close Data", false); JFreeChart highLowChart = buildChart(datasetHighLow, "High/Low Data", true); JFreeChart highLowDifChart = buildDifferenceChart(datasetHighLow, "High/Low Difference Chart"); // Create this panel this.setLayout(new GridLayout(2, 2)); this.add(new ChartPanel(summaryChart)); this.add(new ChartPanel(openCloseChart)); this.add(new ChartPanel(highLowChart)); this.add(new ChartPanel(highLowDifChart)); } catch (Exception e) { e.printStackTrace(); } }
protected Day getDay(String date) { try { String[] st = date.split("-"); int year = Integer.parseInt(st[0]); int month = Integer.parseInt(st[1]); int day = Integer.parseInt(st[2]); // Build a new Day return new Day(day, month, year); } catch (Exception e) { e.printStackTrace(); } return null; }
public TestTtsp() { try { mote = new MoteIF(PrintStreamMessenger.err); mote.registerListener(new TestTtspMsg(), this); System.out.println("Connecting to basestation...OK"); } catch (Exception e) { System.out.println("Connecting to basestation...FAILED"); e.printStackTrace(); System.exit(2); } System.out.println( "[Reception Time (ms)] [Node] [Beacon] [GlobalTime (ms)] [LocalTime (ms)] [Offset (ms)] [Root] [Period]"); }
public SerializationTest1(String s) { super(s); lastValue = 100D; series = new TimeSeries("Random Data"); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(series); JFreeChart jfreechart = createChart(timeseriescollection); JFreeChart jfreechart1 = null; try { ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); ObjectOutputStream objectoutputstream = new ObjectOutputStream(bytearrayoutputstream); objectoutputstream.writeObject(jfreechart); objectoutputstream.close(); jfreechart = null; Object obj = null; series = null; System.gc(); ObjectInputStream objectinputstream = new ObjectInputStream(new ByteArrayInputStream(bytearrayoutputstream.toByteArray())); jfreechart1 = (JFreeChart) objectinputstream.readObject(); objectinputstream.close(); } catch (Exception exception) { exception.printStackTrace(); } XYPlot xyplot = (XYPlot) jfreechart1.getPlot(); TimeSeriesCollection timeseriescollection1 = (TimeSeriesCollection) xyplot.getDataset(); series = timeseriescollection1.getSeries(0); ChartPanel chartpanel = new ChartPanel(jfreechart1); JButton jbutton = new JButton("Add New Data Item"); jbutton.setActionCommand("ADD_DATA"); jbutton.addActionListener(this); JPanel jpanel = new JPanel(new BorderLayout()); jpanel.add(chartpanel); jpanel.add(jbutton, "South"); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(jpanel); }
private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("EUR/GBP"); try { timeseries.add(new Day(2, 1, 2001), new Double(1.5788D)); timeseries.add(new Day(3, 1, 2001), new Double(1.5912999999999999D)); timeseries.add(new Day(4, 1, 2001), new Double(1.5807D)); timeseries.add(new Day(5, 1, 2001), new Double(1.5710999999999999D)); timeseries.add(new Day(8, 1, 2001), new Double(1.5778000000000001D)); timeseries.add(new Day(9, 1, 2001), new Double(1.5851D)); timeseries.add(new Day(10, 1, 2001), new Double(1.5846D)); timeseries.add(new Day(11, 1, 2001), new Double(1.5727D)); timeseries.add(new Day(12, 1, 2001), new Double(1.5585D)); timeseries.add(new Day(15, 1, 2001), new Double(1.5693999999999999D)); timeseries.add(new Day(16, 1, 2001), new Double(1.5629D)); timeseries.add(new Day(17, 1, 2001), new Double(1.5831D)); timeseries.add(new Day(18, 1, 2001), new Double(1.5624D)); timeseries.add(new Day(19, 1, 2001), new Double(1.5693999999999999D)); timeseries.add(new Day(22, 1, 2001), new Double(1.5615000000000001D)); timeseries.add(new Day(23, 1, 2001), new Double(1.5656000000000001D)); timeseries.add(new Day(24, 1, 2001), new Double(1.5794999999999999D)); timeseries.add(new Day(25, 1, 2001), new Double(1.5851999999999999D)); timeseries.add(new Day(26, 1, 2001), new Double(1.5797000000000001D)); timeseries.add(new Day(29, 1, 2001), new Double(1.5862000000000001D)); timeseries.add(new Day(30, 1, 2001), new Double(1.5803D)); timeseries.add(new Day(31, 1, 2001), new Double(1.5713999999999999D)); timeseries.add(new Day(1, 2, 2001), new Double(1.5717000000000001D)); timeseries.add(new Day(2, 2, 2001), new Double(1.5734999999999999D)); timeseries.add(new Day(5, 2, 2001), new Double(1.5690999999999999D)); timeseries.add(new Day(6, 2, 2001), new Double(1.5676000000000001D)); timeseries.add(new Day(7, 2, 2001), new Double(1.5677000000000001D)); timeseries.add(new Day(8, 2, 2001), new Double(1.5737000000000001D)); timeseries.add(new Day(9, 2, 2001), new Double(1.5653999999999999D)); timeseries.add(new Day(12, 2, 2001), new Double(1.5621D)); timeseries.add(new Day(13, 2, 2001), new Double(1.5761000000000001D)); timeseries.add(new Day(14, 2, 2001), new Double(1.5898000000000001D)); timeseries.add(new Day(15, 2, 2001), new Double(1.6045D)); timeseries.add(new Day(16, 2, 2001), new Double(1.5851999999999999D)); timeseries.add(new Day(19, 2, 2001), new Double(1.5704D)); timeseries.add(new Day(20, 2, 2001), new Double(1.5891999999999999D)); timeseries.add(new Day(21, 2, 2001), new Double(1.5844D)); timeseries.add(new Day(22, 2, 2001), new Double(1.5933999999999999D)); timeseries.add(new Day(23, 2, 2001), new Double(1.5951D)); timeseries.add(new Day(26, 2, 2001), new Double(1.5848D)); timeseries.add(new Day(27, 2, 2001), new Double(1.5706D)); timeseries.add(new Day(28, 2, 2001), new Double(1.5680000000000001D)); timeseries.add(new Day(1, 3, 2001), new Double(1.5645D)); timeseries.add(new Day(2, 3, 2001), new Double(1.5753999999999999D)); timeseries.add(new Day(5, 3, 2001), new Double(1.5808D)); timeseries.add(new Day(6, 3, 2001), new Double(1.5766D)); timeseries.add(new Day(7, 3, 2001), new Double(1.5755999999999999D)); timeseries.add(new Day(8, 3, 2001), new Double(1.5760000000000001D)); timeseries.add(new Day(9, 3, 2001), new Double(1.5748D)); timeseries.add(new Day(12, 3, 2001), new Double(1.5779000000000001D)); timeseries.add(new Day(13, 3, 2001), new Double(1.5837000000000001D)); timeseries.add(new Day(14, 3, 2001), new Double(1.5886D)); timeseries.add(new Day(15, 3, 2001), new Double(1.5931D)); timeseries.add(new Day(16, 3, 2001), new Double(1.5945D)); timeseries.add(new Day(19, 3, 2001), new Double(1.5880000000000001D)); timeseries.add(new Day(20, 3, 2001), new Double(1.5817000000000001D)); timeseries.add(new Day(21, 3, 2001), new Double(1.5927D)); timeseries.add(new Day(22, 3, 2001), new Double(1.6065D)); timeseries.add(new Day(23, 3, 2001), new Double(1.6006D)); timeseries.add(new Day(26, 3, 2001), new Double(1.6007D)); timeseries.add(new Day(27, 3, 2001), new Double(1.5989D)); timeseries.add(new Day(28, 3, 2001), new Double(1.6134999999999999D)); timeseries.add(new Day(29, 3, 2001), new Double(1.6282000000000001D)); timeseries.add(new Day(30, 3, 2001), new Double(1.609D)); timeseries.add(new Day(2, 4, 2001), new Double(1.6107D)); timeseries.add(new Day(3, 4, 2001), new Double(1.6093D)); timeseries.add(new Day(4, 4, 2001), new Double(1.5880000000000001D)); timeseries.add(new Day(5, 4, 2001), new Double(1.5931D)); timeseries.add(new Day(6, 4, 2001), new Double(1.5968D)); timeseries.add(new Day(9, 4, 2001), new Double(1.6072D)); timeseries.add(new Day(10, 4, 2001), new Double(1.6167D)); timeseries.add(new Day(11, 4, 2001), new Double(1.6214D)); timeseries.add(new Day(12, 4, 2001), new Double(1.6120000000000001D)); timeseries.add(new Day(17, 4, 2001), new Double(1.6229D)); timeseries.add(new Day(18, 4, 2001), new Double(1.6297999999999999D)); timeseries.add(new Day(19, 4, 2001), new Double(1.6158999999999999D)); timeseries.add(new Day(20, 4, 2001), new Double(1.5995999999999999D)); timeseries.add(new Day(23, 4, 2001), new Double(1.6042000000000001D)); timeseries.add(new Day(24, 4, 2001), new Double(1.6061000000000001D)); timeseries.add(new Day(25, 4, 2001), new Double(1.6045D)); timeseries.add(new Day(26, 4, 2001), new Double(1.597D)); timeseries.add(new Day(27, 4, 2001), new Double(1.6094999999999999D)); timeseries.add(new Day(30, 4, 2001), new Double(1.6141000000000001D)); timeseries.add(new Day(1, 5, 2001), new Double(1.6075999999999999D)); timeseries.add(new Day(2, 5, 2001), new Double(1.6076999999999999D)); timeseries.add(new Day(3, 5, 2001), new Double(1.6034999999999999D)); timeseries.add(new Day(4, 5, 2001), new Double(1.6060000000000001D)); timeseries.add(new Day(8, 5, 2001), new Double(1.6177999999999999D)); timeseries.add(new Day(9, 5, 2001), new Double(1.6083000000000001D)); timeseries.add(new Day(10, 5, 2001), new Double(1.6107D)); timeseries.add(new Day(11, 5, 2001), new Double(1.6209D)); timeseries.add(new Day(14, 5, 2001), new Double(1.6228D)); timeseries.add(new Day(15, 5, 2001), new Double(1.6184000000000001D)); timeseries.add(new Day(16, 5, 2001), new Double(1.6167D)); timeseries.add(new Day(17, 5, 2001), new Double(1.6223000000000001D)); timeseries.add(new Day(18, 5, 2001), new Double(1.6305000000000001D)); timeseries.add(new Day(21, 5, 2001), new Double(1.6419999999999999D)); timeseries.add(new Day(22, 5, 2001), new Double(1.6484000000000001D)); timeseries.add(new Day(23, 5, 2001), new Double(1.6547000000000001D)); timeseries.add(new Day(24, 5, 2001), new Double(1.6444000000000001D)); timeseries.add(new Day(25, 5, 2001), new Double(1.6577D)); timeseries.add(new Day(29, 5, 2001), new Double(1.6606000000000001D)); timeseries.add(new Day(30, 5, 2001), new Double(1.6604000000000001D)); timeseries.add(new Day(31, 5, 2001), new Double(1.6772D)); timeseries.add(new Day(1, 6, 2001), new Double(1.6717D)); timeseries.add(new Day(4, 6, 2001), new Double(1.6685000000000001D)); timeseries.add(new Day(5, 6, 2001), new Double(1.6620999999999999D)); timeseries.add(new Day(6, 6, 2001), new Double(1.6459999999999999D)); timeseries.add(new Day(7, 6, 2001), new Double(1.6333D)); timeseries.add(new Day(8, 6, 2001), new Double(1.6265000000000001D)); timeseries.add(new Day(11, 6, 2001), new Double(1.6311D)); timeseries.add(new Day(12, 6, 2001), new Double(1.6237999999999999D)); timeseries.add(new Day(13, 6, 2001), new Double(1.6299999999999999D)); timeseries.add(new Day(14, 6, 2001), new Double(1.6289D)); timeseries.add(new Day(15, 6, 2001), new Double(1.6275999999999999D)); timeseries.add(new Day(18, 6, 2001), new Double(1.6298999999999999D)); timeseries.add(new Day(19, 6, 2001), new Double(1.6353D)); timeseries.add(new Day(20, 6, 2001), new Double(1.6377999999999999D)); timeseries.add(new Day(21, 6, 2001), new Double(1.6567000000000001D)); timeseries.add(new Day(22, 6, 2001), new Double(1.6523000000000001D)); timeseries.add(new Day(25, 6, 2001), new Double(1.6417999999999999D)); timeseries.add(new Day(26, 6, 2001), new Double(1.6429D)); timeseries.add(new Day(27, 6, 2001), new Double(1.6438999999999999D)); timeseries.add(new Day(28, 6, 2001), new Double(1.6605000000000001D)); timeseries.add(new Day(29, 6, 2001), new Double(1.6598999999999999D)); timeseries.add(new Day(2, 7, 2001), new Double(1.6727000000000001D)); timeseries.add(new Day(3, 7, 2001), new Double(1.6619999999999999D)); timeseries.add(new Day(4, 7, 2001), new Double(1.6628000000000001D)); timeseries.add(new Day(5, 7, 2001), new Double(1.673D)); timeseries.add(new Day(6, 7, 2001), new Double(1.6649D)); timeseries.add(new Day(9, 7, 2001), new Double(1.6603000000000001D)); timeseries.add(new Day(10, 7, 2001), new Double(1.6489D)); timeseries.add(new Day(11, 7, 2001), new Double(1.6420999999999999D)); timeseries.add(new Day(12, 7, 2001), new Double(1.6497999999999999D)); timeseries.add(new Day(13, 7, 2001), new Double(1.6447000000000001D)); timeseries.add(new Day(16, 7, 2001), new Double(1.6373D)); timeseries.add(new Day(17, 7, 2001), new Double(1.6443000000000001D)); timeseries.add(new Day(18, 7, 2001), new Double(1.6246D)); timeseries.add(new Day(19, 7, 2001), new Double(1.6294999999999999D)); timeseries.add(new Day(20, 7, 2001), new Double(1.6362000000000001D)); timeseries.add(new Day(23, 7, 2001), new Double(1.6348D)); timeseries.add(new Day(24, 7, 2001), new Double(1.6242000000000001D)); timeseries.add(new Day(25, 7, 2001), new Double(1.6241000000000001D)); timeseries.add(new Day(26, 7, 2001), new Double(1.6281000000000001D)); timeseries.add(new Day(27, 7, 2001), new Double(1.6295999999999999D)); timeseries.add(new Day(30, 7, 2001), new Double(1.6278999999999999D)); timeseries.add(new Day(31, 7, 2001), new Double(1.6299999999999999D)); timeseries.add(new Day(1, 8, 2001), new Double(1.629D)); timeseries.add(new Day(2, 8, 2001), new Double(1.6236999999999999D)); timeseries.add(new Day(3, 8, 2001), new Double(1.6137999999999999D)); timeseries.add(new Day(6, 8, 2001), new Double(1.6121000000000001D)); timeseries.add(new Day(7, 8, 2001), new Double(1.617D)); timeseries.add(new Day(8, 8, 2001), new Double(1.6134999999999999D)); timeseries.add(new Day(9, 8, 2001), new Double(1.5995999999999999D)); timeseries.add(new Day(10, 8, 2001), new Double(1.5931D)); timeseries.add(new Day(13, 8, 2001), new Double(1.5828D)); timeseries.add(new Day(14, 8, 2001), new Double(1.5824D)); timeseries.add(new Day(15, 8, 2001), new Double(1.5783D)); timeseries.add(new Day(16, 8, 2001), new Double(1.581D)); timeseries.add(new Day(17, 8, 2001), new Double(1.5761000000000001D)); timeseries.add(new Day(20, 8, 2001), new Double(1.5831D)); timeseries.add(new Day(21, 8, 2001), new Double(1.587D)); timeseries.add(new Day(22, 8, 2001), new Double(1.5808D)); timeseries.add(new Day(23, 8, 2001), new Double(1.5845D)); timeseries.add(new Day(24, 8, 2001), new Double(1.5844D)); timeseries.add(new Day(28, 8, 2001), new Double(1.5924D)); timeseries.add(new Day(29, 8, 2001), new Double(1.595D)); timeseries.add(new Day(30, 8, 2001), new Double(1.5941000000000001D)); timeseries.add(new Day(31, 8, 2001), new Double(1.5968D)); timeseries.add(new Day(3, 9, 2001), new Double(1.6020000000000001D)); timeseries.add(new Day(4, 9, 2001), new Double(1.6235999999999999D)); timeseries.add(new Day(5, 9, 2001), new Double(1.6352D)); timeseries.add(new Day(6, 9, 2001), new Double(1.6302000000000001D)); timeseries.add(new Day(7, 9, 2001), new Double(1.6180000000000001D)); timeseries.add(new Day(10, 9, 2001), new Double(1.6217999999999999D)); timeseries.add(new Day(11, 9, 2001), new Double(1.6182000000000001D)); timeseries.add(new Day(12, 9, 2001), new Double(1.6156999999999999D)); timeseries.add(new Day(13, 9, 2001), new Double(1.6171D)); timeseries.add(new Day(14, 9, 2001), new Double(1.5960000000000001D)); timeseries.add(new Day(17, 9, 2001), new Double(1.5952D)); timeseries.add(new Day(18, 9, 2001), new Double(1.5863D)); timeseries.add(new Day(19, 9, 2001), new Double(1.579D)); timeseries.add(new Day(20, 9, 2001), new Double(1.5810999999999999D)); timeseries.add(new Day(21, 9, 2001), new Double(1.5916999999999999D)); timeseries.add(new Day(24, 9, 2001), new Double(1.6005D)); timeseries.add(new Day(25, 9, 2001), new Double(1.5914999999999999D)); timeseries.add(new Day(26, 9, 2001), new Double(1.6012D)); timeseries.add(new Day(27, 9, 2001), new Double(1.6032D)); timeseries.add(new Day(28, 9, 2001), new Double(1.6133D)); timeseries.add(new Day(1, 10, 2001), new Double(1.6147D)); timeseries.add(new Day(2, 10, 2001), new Double(1.6002000000000001D)); timeseries.add(new Day(3, 10, 2001), new Double(1.6041000000000001D)); timeseries.add(new Day(4, 10, 2001), new Double(1.6172D)); timeseries.add(new Day(5, 10, 2001), new Double(1.6121000000000001D)); timeseries.add(new Day(8, 10, 2001), new Double(1.6044D)); timeseries.add(new Day(9, 10, 2001), new Double(1.5973999999999999D)); timeseries.add(new Day(10, 10, 2001), new Double(1.5914999999999999D)); timeseries.add(new Day(11, 10, 2001), new Double(1.6022000000000001D)); timeseries.add(new Day(12, 10, 2001), new Double(1.6013999999999999D)); timeseries.add(new Day(15, 10, 2001), new Double(1.5942000000000001D)); timeseries.add(new Day(16, 10, 2001), new Double(1.5925D)); timeseries.add(new Day(17, 10, 2001), new Double(1.6007D)); timeseries.add(new Day(18, 10, 2001), new Double(1.6000000000000001D)); timeseries.add(new Day(19, 10, 2001), new Double(1.603D)); timeseries.add(new Day(22, 10, 2001), new Double(1.6013999999999999D)); timeseries.add(new Day(23, 10, 2001), new Double(1.5994999999999999D)); timeseries.add(new Day(24, 10, 2001), new Double(1.5951D)); timeseries.add(new Day(25, 10, 2001), new Double(1.5952999999999999D)); timeseries.add(new Day(26, 10, 2001), new Double(1.6056999999999999D)); timeseries.add(new Day(29, 10, 2001), new Double(1.6051D)); timeseries.add(new Day(30, 10, 2001), new Double(1.6027D)); timeseries.add(new Day(31, 10, 2001), new Double(1.6144000000000001D)); timeseries.add(new Day(1, 11, 2001), new Double(1.6138999999999999D)); timeseries.add(new Day(2, 11, 2001), new Double(1.6189D)); timeseries.add(new Day(5, 11, 2001), new Double(1.6248D)); timeseries.add(new Day(6, 11, 2001), new Double(1.6267D)); timeseries.add(new Day(7, 11, 2001), new Double(1.6281000000000001D)); timeseries.add(new Day(8, 11, 2001), new Double(1.631D)); timeseries.add(new Day(9, 11, 2001), new Double(1.6313D)); timeseries.add(new Day(12, 11, 2001), new Double(1.6272D)); timeseries.add(new Day(13, 11, 2001), new Double(1.6361000000000001D)); timeseries.add(new Day(14, 11, 2001), new Double(1.6323000000000001D)); timeseries.add(new Day(15, 11, 2001), new Double(1.6252D)); timeseries.add(new Day(16, 11, 2001), new Double(1.6141000000000001D)); timeseries.add(new Day(19, 11, 2001), new Double(1.6086D)); timeseries.add(new Day(20, 11, 2001), new Double(1.6054999999999999D)); timeseries.add(new Day(21, 11, 2001), new Double(1.6132D)); timeseries.add(new Day(22, 11, 2001), new Double(1.6073999999999999D)); timeseries.add(new Day(23, 11, 2001), new Double(1.6065D)); timeseries.add(new Day(26, 11, 2001), new Double(1.6061000000000001D)); timeseries.add(new Day(27, 11, 2001), new Double(1.6039000000000001D)); timeseries.add(new Day(28, 11, 2001), new Double(1.6069D)); timeseries.add(new Day(29, 11, 2001), new Double(1.6044D)); timeseries.add(new Day(30, 11, 2001), new Double(1.5928D)); } catch (Exception exception) { System.err.println(exception.getMessage()); } return new TimeSeriesCollection(timeseries); }