コード例 #1
0
  /**
   * draw lines
   *
   * <p>ラインを書く
   *
   * <p>绘制线条
   *
   * @param canvas
   */
  protected void drawAreas(Canvas canvas) {
    // distance between two points
    float lineLength = ((super.getWidth() - super.getAxisMarginLeft()) / displayNumber) - 1;
    // start point‘s X
    float startX;
    float lastY = 0;
    float lastX = 0;

    LineEntity<DateValueEntity> line1 = (LineEntity<DateValueEntity>) bandData.get(0);
    LineEntity<DateValueEntity> line2 = (LineEntity<DateValueEntity>) bandData.get(1);

    if (line1.isDisplay() && line2.isDisplay()) {
      Paint mPaint = new Paint();
      mPaint.setColor(line1.getLineColor());
      mPaint.setAlpha(70);
      mPaint.setAntiAlias(true);
      List<DateValueEntity> line1Data = line1.getLineData();
      List<DateValueEntity> line2Data = line2.getLineData();
      // set start point’s X
      startX = super.getAxisMarginLeft() + lineLength / 2f;
      Path areaPath = new Path();
      if (line1Data != null && line2Data != null) {
        for (int j = displayFrom; j < displayFrom + displayNumber; j++) {
          float value1 = line1Data.get(j).getValue();
          float value2 = line2Data.get(j).getValue();

          // calculate Y
          float valueY1 =
              (float)
                  ((1f - (value1 - this.getMinValue()) / (this.getMaxValue() - this.getMinValue()))
                      * (super.getHeight() - super.getAxisMarginBottom()));
          float valueY2 =
              (float)
                  ((1f - (value2 - this.getMinValue()) / (this.getMaxValue() - this.getMinValue()))
                      * (super.getHeight() - super.getAxisMarginBottom()));

          // 绘制线条路径
          if (j == displayFrom) {
            areaPath.moveTo(startX, valueY1);
            areaPath.lineTo(startX, valueY2);
            areaPath.moveTo(startX, valueY1);
          } else {
            areaPath.lineTo(startX, valueY1);
            areaPath.lineTo(startX, valueY2);
            areaPath.lineTo(lastX, lastY);

            areaPath.close();
            areaPath.moveTo(startX, valueY1);
          }

          lastX = startX;
          lastY = valueY2;
          startX = startX + 1 + lineLength;
        }
        areaPath.close();
        canvas.drawPath(areaPath, mPaint);
      }
    }
  }
コード例 #2
0
  /**
   * draw lines
   *
   * <p>ラインを書く
   *
   * <p>绘制线条
   *
   * @param canvas
   */
  protected void drawBandBorder(Canvas canvas) {
    // distance between two points
    float lineLength = ((super.getWidth() - super.getAxisMarginLeft()) / displayNumber) - 1;
    // start point‘s X
    float startX;

    // draw lines
    for (int i = 0; i < bandData.size(); i++) {
      LineEntity<DateValueEntity> line = (LineEntity<DateValueEntity>) bandData.get(i);
      if (line.isDisplay()) {
        Paint mPaint = new Paint();
        mPaint.setColor(line.getLineColor());
        mPaint.setAntiAlias(true);
        List<DateValueEntity> lineData = line.getLineData();
        // set start point’s X
        startX = super.getAxisMarginLeft() + lineLength / 2f;
        // start point
        PointF ptFirst = null;
        if (lineData != null) {
          for (int j = displayFrom; j < displayFrom + displayNumber; j++) {
            float value = lineData.get(j).getValue();
            // calculate Y
            float valueY =
                (float)
                    ((1f - (value - this.getMinValue()) / (this.getMaxValue() - this.getMinValue()))
                        * (super.getHeight() - super.getAxisMarginBottom()));

            // if is not last point connect to previous point
            if (j > displayFrom) {
              canvas.drawLine(ptFirst.x, ptFirst.y, startX, valueY, mPaint);
            }
            // reset
            ptFirst = new PointF(startX, valueY);
            startX = startX + 1 + lineLength;
          }
        }
      }
    }
  }