예제 #1
0
  /**
   * Set the title of the axis
   *
   * @param s string containing text.
   */
  public void setTitleText(String s) {

    title.setText(s);
  }
예제 #2
0
  /**
   * Draw a Vertical Axis.
   *
   * @param g Graphics context.
   */
  protected void drawVAxis(Graphics g) {

    Graphics lg;

    int i;

    int j;

    int x0, y0, x1, y1;

    int direction;

    int tempOffset = 0;

    double minor_step;

    double minor;

    Color c;

    double vmin = minimum * 1.001;

    double vmax = maximum * 1.001;

    double scale = (amax.y - amin.y) / (maximum - minimum);

    double val;

    //          System.out.println("Drawing Vertical Axis!");
    if (axiscolor != null) {
      g.setColor(axiscolor);
    }

    g.drawLine(amin.x, amin.y, amax.x, amax.y);

    if (position == RIGHT) {
      direction = -1;
    } else {
      direction = 1;
    }

    minor_step = label_step / (minor_tic_count + 1);

    val = label_start;

    for (i = 0; i < label_count; i++) {

      if (val >= vmin && val <= vmax) {

        x0 = amin.x;

        y0 = amax.y - (int) ((val - minimum) * scale);

        if (Math.abs(label_value[i]) <= 0.0001 && drawzero) {

          c = g.getColor();

          if (zerocolor != null) {
            g.setColor(zerocolor);
          }

          g.drawLine(x0, y0, x0 + data_window.width * direction, y0);

          g.setColor(c);

        } else if (paintGrid) {

          c = g.getColor();

          if (gridcolor != null) {
            g.setColor(gridcolor);
          }

          if (transparency != 255) {

            Graphics2D g2d = (Graphics2D) g;

            Paint pn = g2d.getPaint();

            if (gridcolor != null) {
              g.setColor(
                  new Color(
                      gridcolor.getRed(),
                      gridcolor.getGreen(),
                      gridcolor.getBlue(),
                      (int) transparency));
            }
          }

          if (!(i == 0 && dropFirstGridLine)) {
            g.drawLine(x0, y0, x0 + data_window.width * direction, y0);
          }

          g.setColor(c);
        }

        x1 = x0 + major_tic_size * direction;

        y1 = y0;

        g.drawLine(x0, y0, x1, y1);

        if (TICS_IN_BOTH_ENDS) {
          g.drawLine(
              x0 + data_window.width * direction - major_tic_size,
              y0,
              x0 + data_window.width * direction,
              y1);
        }
      }

      minor = val + minor_step;

      for (j = 0; j < minor_tic_count; j++) {

        if (minor >= vmin && minor <= vmax) {

          x0 = amin.x;

          y0 = amax.y - (int) ((minor - minimum) * scale);

          if (paintGrid) {

            c = g.getColor();

            if (gridcolor != null) {
              g.setColor(gridcolor);
            }

            if (transparency != 255) {

              Graphics2D g2d = (Graphics2D) g;

              Paint pn = g2d.getPaint();

              if (gridcolor != null) {
                g.setColor(
                    new Color(
                        gridcolor.getRed(),
                        gridcolor.getGreen(),
                        gridcolor.getBlue(),
                        (int) transparency));
              }
            }

            g.drawLine(x0, y0, x0 + data_window.width * direction, y0);

            g.setColor(c);
          }

          x1 = x0 + minor_tic_size * direction;

          y1 = y0;

          g.drawLine(x0, y0, x1, y1);

          if (TICS_IN_BOTH_ENDS) {
            g.drawLine(
                x0 + data_window.width * direction - minor_tic_size,
                y0,
                x0 + data_window.width * direction,
                y1);
          }
        }

        minor += minor_step;
      }

      val += label_step;
    }

    val = label_start;

    for (i = 0; i < label_count; i++) {

      if (val >= vmin && val <= vmax) {

        x0 = amin.x + tempOffset;

        y0 = amax.y - (int) ((val - minimum) * scale) + label.getAscent(g) / 2;

        if (position == RIGHT) {

          label.setText(" " + label_string[i]);

          label.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          label.setText(label_string[i] + " ");

          label.draw(g, x0, y0, ChartLabel.RIGHT);
        }
      }

      val += label_step;
    }

    /*
     *
     * if( !exponent.isNull() ) {
     *
     *
     *
     * y0 = amin.y;
     *
     *
     *
     * if(position == RIGHT ) {
     *
     * x0 = amin.x + max_label_width + exponent.charWidth(g,' ');
     *
     * exponent.draw(g,x0,y0,ChartLabel.LEFT);
     *
     * } else {
     *
     *
     *
     * x0 = amin.x - exponent.getWidth(g)-exponent.charWidth(g,' ');
     *
     * //x0 = amin.x - max_label_width - exponent.charWidth(g,' ');
     *
     * exponent.draw(g,x0,y0,ChartLabel.RIGHT);
     *
     * }
     *
     *
     *
     * }
     *
     */
    if (!title.isNull()) {

      y0 = amin.y + (amax.y - amin.y) / 2;

      if (title.getRotation() == 0 || title.getRotation() == 180) {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width + title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          x0 = amin.x - max_label_width - title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.RIGHT);
        }

      } else {

        title.setJustification(ChartLabel.CENTER);

        if (position == RIGHT) {

          x0 = amin.x + max_label_width - title.getLeftEdge(g) + +title.charWidth(g, ' ');

        } else {

          x0 = amin.x - max_label_width - title.getRightEdge(g) - title.charWidth(g, ' ');
        }

        title.draw(g, x0, y0);
      }
    }

    if (!exponent.isNull()) {

      y0 = amin.y + exponent.getWidth(g);

      if (title.getRotation() == 0 || title.getRotation() == 180) {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width + title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          x0 = amin.x - max_label_width - title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.RIGHT);
        }

      } else {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width - title.getLeftEdge(g) + +title.charWidth(g, ' ');

        } else {

          x0 = amin.x - max_label_width - title.getRightEdge(g) - title.charWidth(g, ' ');
        }

        exponent.setBackground(Color.red);

        exponent.setRotation(90);

        exponent.setFontSize(12);

        exponent.setFontStyle(1);

        exponent.setFontName("TIMES NEW ROMAN");

        exponent.draw(g, x0, y0);
      }
    }
  }