Package plotter.xy

Examples of plotter.xy.LinearXYAxis


    final XYPlotFrame frame = new XYPlotFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setup();
    Timer timer = new Timer();

    final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis();
    final XYAxis yAxis = frame.getYAxis();
    xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
    xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS")));

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final SimpleXYDataset d = new SimpleXYDataset(line);
    d.setMaxCapacity(1000);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
    marker.setForeground(Color.yellow);
    XYPlotContents contents = frame.getContents();
    contents.add(marker);
    frame.addPlotLine(line);

    yAxis.setStart(-1.2);
    yAxis.setEnd(1.2);
    xAxis.setStart(0);
    xAxis.setEnd(10);

    frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>"));
    frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss}  <b>&Delta;y:</b> {1}</html>"));

    for(int x = 0; x < 900; x++) {
      double x2 = x / 10.0;
      double y2 = Math.sin(x2 / 10.0);
      d.add(x2, y2);
    }
    timer.schedule(new TimerTask() {
      int x = 0;


      @Override
      public void run() {
        x++;
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            long now = System.currentTimeMillis();
            xAxis.setStart(now - 5000);
            xAxis.setEnd(now + 5000);
            double x2 = now;
            double y2 = Math.sin(x2 / 2000.0);
            d.add(x2, y2);
            marker.setValue(x2);
          }
View Full Code Here


    final SimpleXYDataset[][] datasets = new SimpleXYDataset[numPlots][linesPerPlot];
    SlopeLine slopeLine = new SlopeLine();
    slopeLine.setForeground(Color.white);
    for(int i = 0; i < numPlots; i++) {
      final XYPlot plot = new XYPlot();
      final XYAxis xAxis = new LinearXYAxis(XYDimension.X);
      final XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
      xAxis.setPreferredSize(new Dimension(1, 30));
      yAxis.setPreferredSize(new Dimension(40, 1));
      xAxis.setForeground(Color.white);
      yAxis.setForeground(Color.white);
      xAxis.setTextMargin(10);
      yAxis.setTextMargin(10);
      plot.add(xAxis);
      plot.add(yAxis);
      plot.setXAxis(xAxis);
      plot.setYAxis(yAxis);
      plot.setBackground(Color.darkGray);
      XYGrid grid = new XYGrid(xAxis, yAxis);
      grid.setForeground(Color.lightGray);
      XYPlotContents contents = new XYPlotContents();
      contents.setBackground(Color.black);
      plot.add(contents);
      contents.add(grid);
      plot.setPreferredSize(new Dimension(150, 100));

      new DefaultXYLayoutGenerator().generateLayout(plot);

      for(int j = 0; j < linesPerPlot; j++) {
        final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
        line.setForeground(Color.white);
        final SimpleXYDataset d = new SimpleXYDataset(line);
        d.setMaxCapacity(1000);
        d.setXData(line.getXData());
        d.setYData(line.getYData());
        contents.add(line);

        for(int x = 0; x < 900; x++) {
          double x2 = x / 10.0;
          double y2 = Math.sin(x2 / 10.0 + Math.PI * j / (double) linesPerPlot);
          d.add(x2, y2);
        }
        datasets[i][j] = d;
      }
      slopeLine.attach(plot);

      yAxis.setStart(-1.2);
      yAxis.setEnd(1.2);
      xAxis.setStart(0);
      xAxis.setEnd(10);

      container.add(plot);

View Full Code Here

    XYPlotFrame frame = new XYPlotFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setup();
    Timer timer = new Timer();

    final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis();
    final XYAxis yAxis = frame.getYAxis();
    xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
    final long start = System.currentTimeMillis();
    xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS"), start));

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setXData(new DoubleDataFloat());
    line.setYData(new DoubleDataFloat());
    line.setForeground(Color.white);
    final SimpleXYDataset d = new SimpleXYDataset(line);
    d.setMaxCapacity(1000);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
    marker.setForeground(Color.yellow);
    XYPlotContents contents = frame.getContents();
    contents.add(marker);
    final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5);
    marker2.setForeground(Color.red);
    contents.add(marker2);
    frame.addPlotLine(line);

    yAxis.setStart(-1.2);
    yAxis.setEnd(1.2);
    xAxis.setStart(0);
    xAxis.setEnd(10);

    final MessageFormat f = new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>");
    frame.getLocationDisplay().setFormat(new Format() {
      @Override
      public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
        Object[] args = (Object[]) obj;
        double d = ((Number) args[0]).doubleValue();
        Object[] args2 = new Object[] { d + start, args[1] };
        return f.format(args2, toAppendTo, pos);
      }

      @Override
      public Object parseObject(String source, ParsePosition pos) {
        throw new UnsupportedOperationException();
      }
    });
    frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss}  <b>&Delta;y:</b> {1}</html>"));

    for(int x = 0; x < 900; x++) {
      double x2 = x / 10.0;
      double y2 = Math.sin(x2 / 10.0);
      d.add(x2, y2);
    }
    timer.schedule(new TimerTask() {
      int x = 0;


      @Override
      public void run() {
        x++;
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            long now = System.currentTimeMillis() - start;
            xAxis.setStart(now / 1000 * 1000 - 9000);
            xAxis.setEnd(now / 1000 * 1000 + 1000);
            double x2 = now;
            double y2 = Math.sin(x2 / 2000.0);
            d.add(x2, y2);
            marker.setValue(x2);
            marker2.setValue(y2);
View Full Code Here

    XYPlotFrame frame = new XYPlotFrame() {
      private static final long serialVersionUID = 1L;

      @Override
      protected XYAxis createYAxis() {
        LinearXYAxis axis = new LinearXYAxis(XYDimension.Y);
        axis.setTickMarkCalculator(new LogTickMarkCalculator());
        axis.setFormat(new ExpFormat(new DecimalFormat("#.#")));
        return axis;
      }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setup();
View Full Code Here

    contentPane.add(plot);
  }


  protected XYAxis createYAxis() {
    return new LinearXYAxis(XYDimension.Y);
  }
View Full Code Here

    return new LinearXYAxis(XYDimension.Y);
  }


  protected XYAxis createXAxis() {
    return new LinearXYAxis(XYDimension.X);
  }
View Full Code Here

    XYPlotFrame frame = new XYPlotFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setup();
    Timer timer = new Timer();

    final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis();
    final XYAxis yAxis = frame.getYAxis();
    xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
    xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS")));

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final SimpleXYDataset d = new SimpleXYDataset(line);
    d.setMaxCapacity(1000);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
    marker.setForeground(Color.yellow);
    XYPlotContents contents = frame.getContents();
    contents.add(marker);
    final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5);
    marker2.setForeground(Color.red);
    contents.add(marker2);
    frame.addPlotLine(line);

    yAxis.setStart(-1.2);
    yAxis.setEnd(1.2);
    xAxis.setStart(0);
    xAxis.setEnd(10);

    frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>"));
    frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss}  <b>&Delta;y:</b> {1}</html>"));

    for(int x = 0; x < 900; x++) {
      double x2 = x / 10.0;
      double y2 = Math.sin(x2 / 10.0);
      d.add(x2, y2);
    }
    timer.schedule(new TimerTask() {
      int x = 0;


      @Override
      public void run() {
        x++;
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            long now = System.currentTimeMillis();
            xAxis.setStart(now / 1000 * 1000 - 9000);
            xAxis.setEnd(now / 1000 * 1000 + 1000);
            double x2 = now;
            double y2 = Math.sin(x2 / 2000.0);
            d.add(x2, y2);
            marker.setValue(x2);
            marker2.setValue(y2);
View Full Code Here

    XYPlotFrame frame = new XYPlotFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setup();
    Timer timer = new Timer();

    final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis();
    final XYAxis yAxis = frame.getYAxis();
    xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
    xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS")));

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final CompressingXYDataset d = new CompressingXYDataset(line, new DefaultCompressor());
    d.setTruncationPoint(0);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
    marker.setForeground(Color.yellow);
    XYPlotContents contents = frame.getContents();
    contents.add(marker);
    final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5);
    marker2.setForeground(Color.red);
    contents.add(marker2);
    frame.addPlotLine(line);

    yAxis.setStart(-1.2);
    yAxis.setEnd(1.2);
    xAxis.setStart(0);
    xAxis.setEnd(10);

    frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>"));
    frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss}  <b>&Delta;y:</b> {1}</html>"));

    for(int x = 0; x < 900; x++) {
      double x2 = x / 10.0;
      double y2 = Math.sin(x2 / 10.0);
      d.add(x2, y2);
    }
    timer.schedule(new TimerTask() {
      int x = 0;
      long startTime = System.currentTimeMillis();


      @Override
      public void run() {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            long now = System.currentTimeMillis();
            xAxis.setStart(now / 1000 * 1000 - 9000);
            xAxis.setEnd(now / 1000 * 1000 + 1000);
            d.setTruncationPoint(xAxis.getStart());
            for(int i = 0; i < 10; i++) {
              double x2 = now + i;
              double y2 = Math.sin(x2 / 2000.0);
              d.add(x2, y2);
              marker.setValue(x2);
              marker2.setValue(y2);
              x++;
              if(x % 100 == 0) {
                System.out.println("Dataset size: " + d.getPointCount());
                System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth());
                System.out.println("Points per second: " + 1000 * x / (double) (now - startTime));
              }
            }
          }
        });
      }
    }, 10, 10);

    line.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        d.setCompressionOffset(xAxis.getStart());
        d.setCompressionScale((xAxis.getEnd() - xAxis.getStart()) / xAxis.getWidth());
      }
    });

    frame.setSize(400, 300);
    frame.setVisible(true);
View Full Code Here

  }


  private static SimpleXYDataset createPlot(Container contentPane) {
    final XYPlot plot = new XYPlot();
    XYAxis xAxis = new LinearXYAxis(XYDimension.X);
    XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
    xAxis.setPreferredSize(new Dimension(1, 40));
    yAxis.setPreferredSize(new Dimension(40, 1));
    xAxis.setForeground(Color.white);
    yAxis.setForeground(Color.white);
    xAxis.setTextMargin(10);
    yAxis.setTextMargin(10);
    plot.add(xAxis);
    plot.add(yAxis);
    plot.setXAxis(xAxis);
    plot.setYAxis(yAxis);
    plot.setBackground(Color.darkGray);
    XYPlotContents contents = new XYPlotContents();
    contents.setBackground(Color.black);
    plot.setBackground(Color.darkGray);
    XYGrid grid = new XYGrid(xAxis, yAxis);
    grid.setForeground(Color.lightGray);
    contents.add(grid);
    plot.add(contents);
    plot.setPreferredSize(new Dimension(150, 100));
   
    contentPane.setBackground(Color.darkGray);
   
    XYLocationDisplay locationDisplay = new XYLocationDisplay();
    // This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty.
    // Note that mimimumSize does not work for some reason.
    locationDisplay.setText("Ag");
    Dimension size = locationDisplay.getPreferredSize();
    size.width = 100;
    locationDisplay.setText("");
    locationDisplay.setPreferredSize(size);
    // End hack
    locationDisplay.setForeground(Color.white);
    locationDisplay.setFont(new Font("Arial", 0, 12));
    locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1}</html>"));
    locationDisplay.attach(plot);
    plot.add(locationDisplay);

    SlopeLine slopeLine = new SlopeLine();
    slopeLine.setForeground(Color.white);
    slopeLine.attach(plot);

    SlopeLineDisplay slopeLineDisplay = new SlopeLineDisplay();
    slopeLine.addListenerForPlot(plot, slopeLineDisplay);
    slopeLineDisplay.setFont(new Font("Arial", 0, 12));
    slopeLineDisplay.setForeground(Color.white);
    slopeLineDisplay.setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0}  <b>&Delta;y:</b> {1}</html>"));
    plot.add(slopeLineDisplay);

    contentPane.add(plot);
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));

    new DefaultXYLayoutGenerator().generateLayout(plot);

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final SimpleXYDataset d = new SimpleXYDataset(line);
    d.setMaxCapacity(10000);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    contents.add(line);
    contents.setComponentZOrder(grid, contents.getComponentCount() - 1);

    yAxis.setStart(-20);
    yAxis.setEnd(20);
    xAxis.setStart(0);
    xAxis.setEnd(10000);
    return d;
  }
View Full Code Here

  }


  private static SimpleXYDataset createPlot(Container contentPane, boolean invertX, boolean invertY) {
    final XYPlot plot = new XYPlot();
    XYAxis xAxis = new LinearXYAxis(XYDimension.X);
    XYAxis yAxis = new LinearXYAxis(XYDimension.Y);
    xAxis.setPreferredSize(new Dimension(1, 40));
    yAxis.setPreferredSize(new Dimension(40, 1));
    xAxis.setForeground(Color.white);
    yAxis.setForeground(Color.white);
    xAxis.setTextMargin(10);
    yAxis.setTextMargin(10);
    plot.add(xAxis);
    plot.add(yAxis);
    plot.setXAxis(xAxis);
    plot.setYAxis(yAxis);
    plot.setBackground(Color.darkGray);
    XYPlotContents contents = new XYPlotContents();
    contents.setBackground(Color.black);
    plot.setBackground(Color.darkGray);
    XYGrid grid = new XYGrid(xAxis, yAxis);
    grid.setForeground(Color.lightGray);
    contents.add(grid);
    plot.add(contents);
    plot.setPreferredSize(new Dimension(150, 100));
   
    contentPane.setBackground(Color.darkGray);
   
    XYLocationDisplay locationDisplay = new XYLocationDisplay();
    // This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty.
    // Note that mimimumSize does not work for some reason.
    locationDisplay.setText("Ag");
    Dimension size = locationDisplay.getPreferredSize();
    size.width = 100;
    locationDisplay.setText("");
    locationDisplay.setPreferredSize(size);
    // End hack
    locationDisplay.setForeground(Color.white);
    locationDisplay.setFont(new Font("Arial", 0, 12));
    locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1}</html>"));
    locationDisplay.attach(plot);
    plot.add(locationDisplay);

    SlopeLine slopeLine = new SlopeLine();
    slopeLine.setForeground(Color.white);
    slopeLine.attach(plot);
   
    SlopeLineDisplay slopeLineDisplay = new SlopeLineDisplay();
    slopeLine.addListenerForPlot(plot, slopeLineDisplay);
    slopeLineDisplay.setFont(new Font("Arial", 0, 12));
    slopeLineDisplay.setForeground(Color.white);
    slopeLineDisplay.setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0}  <b>&Delta;y:</b> {1}</html>"));
    plot.add(slopeLineDisplay);

    new DefaultXYLayoutGenerator().generateLayout(plot);

    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS));
    contentPane.add(plot);

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final SimpleXYDataset d = new SimpleXYDataset(line);
    d.setMaxCapacity(10000);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    contents.add(line);
    contents.setComponentZOrder(grid, contents.getComponentCount() - 1);

    if(invertY) {
      yAxis.setStart(200);
      yAxis.setEnd(0);
    } else {
      yAxis.setStart(0);
      yAxis.setEnd(200);
    }
    if(invertX) {
      xAxis.setStart(5);
      xAxis.setEnd(0);
    } else {
View Full Code Here

TOP

Related Classes of plotter.xy.LinearXYAxis

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.