Beispiel #1
0
 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;
 }
  /** wipes all data */
  public void wipeAll() {

    // wipes all

    dataset1.removeAllSeries();
    x1 = new TimeSeries("symbol", FixedMillisecond.class);
    dataset1.addSeries(x1);

    current = new Candle();

    candletime = -1;
    hld.wipe();
  }
  private static XYDataset createForceDataset(int i) {
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    TimeSeries timeseries = new TimeSeries("Wind Force", org.jfree.data.time.Minute.class);
    Object obj = new Minute();
    double d = 3D;
    for (int j = 0; j < i; j++) {
      timeseries.add(((RegularTimePeriod) (obj)), d);
      obj = ((RegularTimePeriod) (obj)).next();
      d = Math.max(0.5D, d + (Math.random() - 0.5D) * 0.5D);
    }

    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
  }
Beispiel #4
0
  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();
    }
  }
Beispiel #5
0
  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();
    }
  }
  private static XYDataset createDirectionDataset(int i) {
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    TimeSeries timeseries = new TimeSeries("Wind Direction", org.jfree.data.time.Minute.class);
    Object obj = new Minute();
    double d = 180D;
    for (int j = 0; j < i; j++) {
      timeseries.add(((RegularTimePeriod) (obj)), d);
      obj = ((RegularTimePeriod) (obj)).next();
      d += (Math.random() - 0.5D) * 15D;
      if (d < 0.0D) {
        d += 360D;
        continue;
      }
      if (d > 360D) d -= 360D;
    }

    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
  }
 private static XYDataset createDataset2A() {
   TimeSeries timeseries = new TimeSeries("Series 2");
   timeseries.add(new Day(3, 3, 2002), 16853.200000000001D);
   timeseries.add(new Day(4, 3, 2002), 19642.299999999999D);
   timeseries.add(new Day(5, 3, 2002), 18253.5D);
   timeseries.add(new Day(6, 3, 2002), 15352.299999999999D);
   timeseries.add(new Day(7, 3, 2002), 13532D);
   timeseries.add(new Day(8, 3, 2002), 12635.299999999999D);
   timeseries.add(new Day(9, 3, 2002), 13998.200000000001D);
   timeseries.add(new Day(10, 3, 2002), 11943.200000000001D);
   timeseries.add(new Day(11, 3, 2002), 16943.900000000001D);
   timeseries.add(new Day(12, 3, 2002), 17843.200000000001D);
   timeseries.add(new Day(13, 3, 2002), 16495.299999999999D);
   timeseries.add(new Day(14, 3, 2002), 17943.599999999999D);
   timeseries.add(new Day(15, 3, 2002), 18500.700000000001D);
   timeseries.add(new Day(16, 3, 2002), 19595.900000000001D);
   TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
   timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE);
   return timeseriescollection;
 }
 private static XYDataset createDataset2B() {
   TimeSeries timeseries = new TimeSeries("Series 2B");
   timeseries.add(new Day(3, 3, 2002), 43.899999999999999D);
   timeseries.add(new Day(4, 3, 2002), 72.599999999999994D);
   timeseries.add(new Day(5, 3, 2002), 89.400000000000006D);
   timeseries.add(new Day(6, 3, 2002), 23.800000000000001D);
   timeseries.add(new Day(7, 3, 2002), 45D);
   timeseries.add(new Day(8, 3, 2002), 65.799999999999997D);
   timeseries.add(new Day(9, 3, 2002), 92.099999999999994D);
   timeseries.add(new Day(10, 3, 2002), 84.700000000000003D);
   timeseries.add(new Day(11, 3, 2002), 77.200000000000003D);
   timeseries.add(new Day(12, 3, 2002), 65.099999999999994D);
   timeseries.add(new Day(13, 3, 2002), 78.5D);
   timeseries.add(new Day(14, 3, 2002), 75.299999999999997D);
   timeseries.add(new Day(15, 3, 2002), 69.900000000000006D);
   timeseries.add(new Day(20, 3, 2002), 56.600000000000001D);
   TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
   timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE);
   return timeseriescollection;
 }
  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();
      }
    }
  }
Beispiel #10
0
 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);
 }
Beispiel #11
0
  public ChartWindow(String title) {

    this.symbol = title;
    thisp = this;
    // initialize the main layout
    setTitle(title);
    mainpanel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    mainpanel.setLayout(gbl);

    // build a toolbar
    //		add a plain status bar
    this.statusLine = new JLabel("Done");
    this.getContentPane().add(statusLine, BorderLayout.SOUTH);

    statusLine.setBackground(new Color(0, 0, 0));
    statusLine.setForeground(new Color(255, 255, 255));
    statusLine.setOpaque(true);

    //
    x1 = new TimeSeries("symbol", FixedMillisecond.class);
    dataset1.addSeries(x1);

    System.out.println("Populated.");

    //
    chart = createChart(dataset1);
    System.out.println("constr.");

    // chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);

    chart.setAntiAlias(false);

    chartPanel = new ChartPanel(chart);

    //

    int i = 0;
    gbc.anchor = gbc.NORTHWEST;
    gbc.fill = gbc.BOTH;
    gbc.weightx = 1;
    gbc.gridx = 0;

    gbc.weighty = 1;
    gbc.gridy = i;
    gbl.setConstraints(chartPanel, gbc);

    mainpanel.add(chartPanel);
    // System.out.println("add");
    setVisible(true);
    setSize(new Dimension(400, 300));

    // chartPanel.setPopupMenu(buildPopupMenu());
    chartPanel.setMouseZoomable(true);
    chartPanel.setHorizontalAxisTrace(true);
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setHorizontalZoom(true);

    chartPanel.setOpaque(true);
    chartPanel.setBackground(new Color(0, 0, 0));

    this.getContentPane().add(mainpanel, BorderLayout.CENTER);

    this.setSize(600, 400);
    this.toFront();
    this.show();
  }
  private void addData(
      JFreeChart chart,
      DSLAMSource source,
      Timeinterval time,
      Serializable filter,
      Properties properties,
      Map<String, Object> colorScheme,
      Properties outputProperties)
      throws IOException {
    if (chart != null) {
      PerformanceCounterDataCollection cData = null;

      long dataSize = 0;

      try {
        cData =
            getPerformanceCounterDataCollection(source, time, filter, properties, outputProperties);
        Collection<PerformanceCounterData> data = null;

        Date d0 = null; // first timestamp for data
        Date d1 = null; // last timestamp for data
        RegularTimePeriod time0 = null;

        if (cData != null) {
          data = cData.getData();

          {
            int l = data.size();
            outputProperties.setProperty("data.count", Integer.toString(l));
          }

          if (data != null && data.size() > 0) {
            dataSize = data.size();

            // Set 'd0':
            {
              // TODO: Avoid assumption "data is sorted"!
              PerformanceCounterData e = data.iterator().next();
              d0 = e.getTimestamp();
            }

            // Set 'd1':
            {
              // TODO: Avoid assumption "data is sorted"!
              for (PerformanceCounterData e : data) {
                d1 = e.getTimestamp();
              }
            }

            time0 = createRegularTimePeriod(d0);
          }
        }

        XYPlot plot = chart.getXYPlot();

        // Set the first dataset:
        {
          TimeSeriesCollection dataset = new TimeSeriesCollection();

          List<Paint> seriesPaint = new ArrayList<Paint>();
          List<Stroke> seriesStroke = new ArrayList<Stroke>();

          // Add series 'ES':
          {
            if (data != null && data.size() > 0) {
              TimeSeries series = new TimeSeries("ES", time0.getClass());

              for (PerformanceCounterData e : data) {
                Date d = e.getTimestamp();
                RegularTimePeriod timePeriod = createRegularTimePeriod(d);

                // Add point:
                {
                  int value = getES(e);

                  addOrUpdate(series, timePeriod, (double) value);
                }
              }

              seriesPaint.add((Paint) colorScheme.get("color.counter.es"));
              seriesStroke.add(STROKE_COUNTER_ES);

              dataset.addSeries(series);
            }
          }

          // Add series 'SES':
          {
            if (data != null && data.size() > 0) {
              TimeSeries series = new TimeSeries("SES", time0.getClass());

              for (PerformanceCounterData e : data) {
                Date d = e.getTimestamp();
                RegularTimePeriod timePeriod = createRegularTimePeriod(d);

                // Add point:
                {
                  int value = getSES(e);

                  addOrUpdate(series, timePeriod, (double) value);
                }
              }

              seriesPaint.add((Paint) colorScheme.get("color.counter.ses"));
              seriesStroke.add(STROKE_COUNTER_SES);

              dataset.addSeries(series);
            }
          }

          // Add series 'US':
          {
            if (data != null && data.size() > 0) {
              TimeSeries series = new TimeSeries("US", time0.getClass());

              for (PerformanceCounterData e : data) {
                Date d = e.getTimestamp();
                RegularTimePeriod timePeriod = createRegularTimePeriod(d);

                // Add point:
                {
                  int value = getUS(e);

                  addOrUpdate(series, timePeriod, (double) value);
                }
              }

              seriesPaint.add((Paint) colorScheme.get("color.counter.us"));
              seriesStroke.add(STROKE_COUNTER_US);

              dataset.addSeries(series);
            }
          }

          // superspeed
          {
            if (data != null && data.size() > 0) {
              TimeSeries series = new TimeSeries("LEFTRS", time0.getClass());
              for (PerformanceCounterData e : data) {
                Date d = e.getTimestamp();
                RegularTimePeriod timePeriod = createRegularTimePeriod(d);
                {
                  int value = getPreviousLEFTRS(e);
                  addOrUpdate(series, timePeriod, (double) value);
                }
              }
              seriesPaint.add((Paint) colorScheme.get("color.counter.previousleftrs"));
              seriesStroke.add(STROKE_COUNTER_US);
              dataset.addSeries(series);
            }
          }
          // ends
          {
            if (data != null && data.size() > 0) {
              boolean showLinearCurve = getShowLinearCurve();

              if (showLinearCurve) {
                // Add series for a linear curve:
                {
                  TimeSeries series = new TimeSeries("Linear", time0.getClass());

                  long t0 = d0.getTime();
                  long t1 = d1.getTime();

                  if (t0 < t1) {
                    long timeX = 15 * 60 * 1000; // 15 minutes intervals
                    // TODO: Read length of intervals from obtained data!

                    double value0 = 0;
                    double value1 = 900;
                    // TODO: Read '900' from obtained data!

                    long timeDelta = t1 - t0;
                    double valueDelta = value1 - value0;

                    long t = t0;
                    int i = 0;

                    while (t <= t1) {
                      Date d = new Date(t);

                      RegularTimePeriod timePeriod = createRegularTimePeriod(d);
                      double value = value0 + ((t - t0) * valueDelta) / timeDelta;

                      // Add point:
                      {
                        addOrUpdate(series, timePeriod, (double) value);
                      }

                      t += timeX;
                      i += 1;
                    }
                  }

                  seriesPaint.add(Color.red);
                  seriesStroke.add(STROKE_COUNTER_DEFAULT);

                  dataset.addSeries(series);
                }
              }
            }
          }

          setDefaultRenderer(chart, colorScheme, 0, seriesPaint, seriesStroke);
          plot.setDataset(0, dataset);
          plot.mapDatasetToRangeAxis(0, 0);
        }
      } finally {
        if (cData != null) {
          cData.dispose();
          cData = null;
        }
      }

      if (outputProperties != null) {
        outputProperties.setProperty("data.count", Long.toString(dataSize));
      }
    }
  }