コード例 #1
0
ファイル: StickChart.java プロジェクト: kchart/Android-Charts
  /**
   * draw sticks
   *
   * <p>スティックを書く
   *
   * <p>绘制柱条
   *
   * @param canvas
   */
  protected void drawSticks(Canvas canvas) {
    float stickWidth =
        ((super.getWidth() - super.getAxisMarginLeft() - super.getAxisMarginRight()) / maxSticksNum)
            - 1;
    float stickX = super.getAxisMarginLeft() + 1;

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

    if (null != StickData) {

      for (int i = 0; i < StickData.size(); i++) {
        StickEntity ohlc = StickData.get(i);

        float highY =
            (float)
                ((1f - (ohlc.getHigh() - minValue) / (maxValue - minValue))
                        * (super.getHeight() - super.getAxisMarginBottom())
                    - super.getAxisMarginTop());
        float lowY =
            (float)
                ((1f - (ohlc.getLow() - minValue) / (maxValue - minValue))
                        * (super.getHeight() - super.getAxisMarginBottom())
                    - super.getAxisMarginTop());

        // 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 = xAxisOffset + stickX + 1 + stickWidth;
      }
    }
  }