Esempio n. 1
0
  /**
   * ******************************************************************* Test main
   * ********************************************************************
   */
  public static void main(String[] args) throws Exception {
    JFrame jf = new JFrame("DotDiagram - Test");
    // bd.setMinMax(0, 200);
    int[] data = new int[100];
    int[] data2 = new int[100];
    int[] data3 = new int[100];

    boolean neg = true;
    int pos = 100;
    int pos2 = 50;
    int pos3 = 0;
    int s = neg ? -10 : 0;
    for (int i = 0; i < 60; i++) {
      pos = pos + (int) (s + 20 * Math.random());
      pos2 = pos2 + (int) (s + 20 * Math.random());
      pos3 = pos3 + (int) (s + 20 * Math.random());
      data[i] = pos;
      data2[i] = pos2;
      data3[i] = pos3;
    }
    DotDiagram bd = setupDiagram(10, data, data2, data3, NORMAL);
    DotDiagram bd2 = setupDiagram(10, data, data2, data3, ADDITIVE);
    DotDiagram bd3 = setupDiagram(10, data, data2, data3, FILLED_ADDITIVE);

    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(600, 200);
    jf.getContentPane().setLayout(new GridLayout(0, 3));
    jf.getContentPane().add(bd);
    jf.getContentPane().add(bd2);
    jf.getContentPane().add(bd3);
    jf.setVisible(true);

    for (int i = 0; i < 20000; i++) {
      Thread.sleep(100);
      pos = pos + (int) (5 - 10 * Math.random());
      pos2 = pos2 + (int) (5 - 10 * Math.random());
      pos3 = pos3 + (int) (5 - 10 * Math.random());

      if (pos < 0) pos = 0;
      if (pos3 < 0) pos3 = 0;

      data[(60 + i) % data.length] = pos;
      data2[(60 + i) % data2.length] = pos2;
      data3[(60 + i) % data3.length] = pos3;
      bd.setData(0, data, i % data.length, 60);
      bd.setData(1, data2, i % data2.length, 60);
      bd.setData(2, data3, i % data3.length, 60);
      bd2.setData(0, data, i % data.length, 60);
      bd2.setData(1, data2, i % data2.length, 60);
      bd2.setData(2, data3, i % data3.length, 60);
      bd3.setData(0, data, i % data.length, 60);
      bd3.setData(1, data2, i % data2.length, 60);
      bd3.setData(2, data3, i % data3.length, 60);
    }
  }
Esempio n. 2
0
 private static DotDiagram setupDiagram(int v, int[] d1, int[] d2, int[] d3, int mode) {
   DotDiagram bd = new DotDiagram(v, mode);
   bd.setDotColor(0, Color.red);
   bd.setDotColor(1, Color.green);
   bd.setDotColor(2, Color.blue);
   bd.addConstant(Color.yellow, 100);
   bd.setShowGrid(true);
   bd.setYLabel("The Y-Axis (" + (mode == NORMAL ? "normal" : "additive") + ')');
   bd.setData(0, d1, 0, 60);
   bd.setData(1, d2, 0, 60);
   bd.setData(2, d3, 0, 60);
   return bd;
 }