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()); } } }