コード例 #1
0
ファイル: Chart.java プロジェクト: feihugis/NetCDF
  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();
    }
  }
コード例 #2
0
ファイル: Chart.java プロジェクト: feihugis/NetCDF
  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();
    }
  }
コード例 #3
0
ファイル: Chart.java プロジェクト: feihugis/NetCDF
  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;
  }
コード例 #4
0
  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]");
  }
コード例 #5
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);
 }