コード例 #1
0
  protected void calcDataValueRange() {

    double maxValue = Double.MIN_VALUE;
    double minValue = Double.MAX_VALUE;

    IMeasurable first = this.stickData.get(0);
    // 第一个stick为停盘的情况
    if (first.getHigh() == 0 && first.getLow() == 0) {

    } else {
      maxValue = first.getHigh();
      minValue = first.getLow();
    }

    // 判断显示为方柱或显示为线条
    for (int i = this.displayFrom; i < this.displayFrom + this.displayNumber; i++) {
      IMeasurable stick = this.stickData.get(i);
      if (stick.getLow() < minValue) {
        minValue = stick.getLow();
      }

      if (stick.getHigh() > maxValue) {
        maxValue = stick.getHigh();
      }
    }

    this.maxValue = maxValue;
    this.minValue = minValue;
  }
コード例 #2
0
  protected void drawSticks(Canvas canvas) {
    if (null == stickData) {
      return;
    }
    if (stickData.size() == 0) {
      return;
    }

    Paint mPaintStick = new Paint();
    mPaintStick.setColor(stickFillColor);

    float stickWidth = getDataQuadrantPaddingWidth() / displayNumber - stickSpacing;
    float stickX = getDataQuadrantPaddingStartX();

    for (int i = displayFrom; i < displayFrom + displayNumber; i++) {
      IMeasurable stick = stickData.get(i);
      float highY =
          (float)
              ((1f - (stick.getHigh() - minValue) / (maxValue - minValue))
                      * (getDataQuadrantPaddingHeight())
                  + getDataQuadrantPaddingStartY());
      float lowY =
          (float)
              ((1f - (stick.getLow() - minValue) / (maxValue - minValue))
                      * (getDataQuadrantPaddingHeight())
                  + getDataQuadrantPaddingStartY());

      // stick or line?
      if (stickWidth >= 2f) {
        canvas.drawRect(stickX, highY, stickX + stickWidth, lowY, mPaintStick);
      } else {
        canvas.drawLine(stickX, highY, stickX, lowY, mPaintStick);
      }

      // next x
      stickX = stickX + stickSpacing + stickWidth;
    }
  }