public void draw(double[] v) { TimeSeries data = new TimeSeries("symbol", FixedMillisecond.class); dataset1.addSeries(data); for (int i = 0; i < v.length; i++) { try { data.add(new FixedMillisecond(i), v[i]); } catch (Exception e) { System.out.println("Unresolved error"); // 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(); } }
public void calcAverage1(int d, Date timestamp) { try { double v = 0; // List l1=x1.getItems(); for (int i = d; i < d + av1; i++) { v += x1.getValue(x1.getItemCount() - (av1 - i)).doubleValue(); } average1.add(new FixedMillisecond(timestamp), v / av1); } catch (Exception e) { // e.printStackTrace(); // System.out.println(timestamp.toString()); } }
/** * actually recalculates the first average (necessary when we change the average settings) * * @param d */ public void recalculateAverage1() { // average1=new TimeSeries("av1", FixedMillisecond.class); average1.delete(0, average1.getItemCount() - 1); for (int z = 0; z < x1.getItemCount(); z++) { try { double v = 0; // List l1=x1.getItems(); for (int i = z; i < z + av1; i++) { v += x1.getValue(x1.getItemCount() - (av1 - i)).doubleValue(); } average1.add(x1.getTimePeriod(z), v / av1); } catch (Exception e) { // e.printStackTrace(); // System.out.println(timestamp.toString()); } } }
private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("L&G European Index Trust"); timeseries.add(new Day(24, 1, 2004), 181.80000000000001D); timeseries.add(new Day(25, 1, 2004), 167.30000000000001D); timeseries.add(new Day(26, 1, 2004), 153.80000000000001D); timeseries.add(new Day(27, 1, 2004), 167.59999999999999D); timeseries.add(new Day(28, 1, 2004), 158.80000000000001D); timeseries.add(new Day(29, 1, 2004), 148.30000000000001D); timeseries.add(new Day(30, 1, 2004), 153.90000000000001D); timeseries.add(new Day(31, 1, 2004), 142.69999999999999D); timeseries.add(new Day(1, 2, 2004), 123.2D); timeseries.add(new Day(2, 2, 2004), 131.80000000000001D); timeseries.add(new Day(3, 2, 2004), 139.59999999999999D); timeseries.add(new Day(4, 2, 2004), 142.90000000000001D); timeseries.add(new Day(5, 2, 2004), 138.69999999999999D); timeseries.add(new Day(6, 2, 2004), 137.30000000000001D); timeseries.add(new Day(7, 2, 2004), 143.90000000000001D); timeseries.add(new Day(8, 2, 2004), 139.80000000000001D); timeseries.add(new Day(9, 2, 2004), 137D); timeseries.add(new Day(10, 2, 2004), 132.80000000000001D); TimeZone timezone = TimeZone.getTimeZone("Pacific/Auckland"); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timezone); timeseriescollection.addSeries(timeseries); timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE); return timeseriescollection; }
/** Call this method every 10 sec and supply a new data point. */ public void update(float f) { counter = (counter + 1) % 360; // 1hour/10sec = 60mins/10sec=3600secs/10sec = 360 sec10.update(f); if (counter % 6 == 0) min.update(f); if (counter == 0) hour.update(f); }