コード例 #1
0
 private void drawLeftAxisLabel(Canvas canvas, int position) {
   Paint axisLabelPaint = labelPaints[LEFT];
   String text = getLeftLabel(position);
   if (position == 0) {
     canvas.drawText(text, 0, -axisLabelPaint.ascent(), axisLabelPaint);
   } else if (position == HORIZONTAL_LINE_NUMBER) {
     float y =
         chartView.getContentHeight() + (axisLabelPaint.ascent() + axisLabelPaint.descent()) / 2;
     canvas.drawText(text, 0, y, axisLabelPaint);
   } else {
     float y = position / (float) HORIZONTAL_LINE_NUMBER * chartView.getContentHeight();
     y = y - (axisLabelPaint.ascent() + axisLabelPaint.descent()) / 2;
     canvas.drawText(text, 0, y, axisLabelPaint);
   }
 }
コード例 #2
0
  private void computeLeftAxisMinAndMax() {
    int start = ((KLineChartView) chartView).getCandleStartIndex();
    int end = ((KLineChartView) chartView).getCandleEndIndex();

    if (start < 0) {
      return;
    }

    List<QuoteData> quoteDataList = chartView.getChartData().getQuoteDataList();
    min = quoteDataList.get(start).low;
    max = quoteDataList.get(start).high;

    for (int i = start; i <= end; i++) {
      QuoteData current = quoteDataList.get(i);
      if (min > current.low) {
        min = current.low;
      }
      if (max < current.high) {
        max = current.high;
      }
    }

    min -= (max - min) * 0.03;
    max += (max - min) * 0.03;
  }
コード例 #3
0
  public KLineAxisRenderer(ChartView chartView) {
    this.chartView = chartView;

    labelTextSize = Util.dp2px(chartView.getResources(), LABEL_SIZE);

    for (int i = 0; i < 4; i++) {
      linePaints[i].setColor(lineColor);
      labelPaints[i].setColor(AXIS_LABEL_COLOR_WHITE);
      labelPaints[i].setTextSize(labelTextSize);
    }
  }
コード例 #4
0
  @Override
  public void drawHorizontalLines(Canvas canvas) {
    Paint paint = linePaints[LEFT];
    paint.setColor(borderColor);
    canvas.drawLine(0, 0, chartView.getWidth(), 0, linePaints[LEFT]);

    paint.setColor(lineColor);
    for (int i = 1; i < HORIZONTAL_LINE_NUMBER; i++) {
      float yPos = (i / (float) HORIZONTAL_LINE_NUMBER) * chartView.getContentHeight();
      canvas.drawLine(0, yPos, chartView.getWidth(), yPos, linePaints[LEFT]);
    }

    paint.setColor(borderColor);
    canvas.drawLine(
        0, chartView.getContentHeight(), chartView.getWidth(), chartView.getContentHeight(), paint);
  }
コード例 #5
0
  @Override
  public void drawVerticalLines(Canvas canvas) {
    Paint linePaint = linePaints[BOTTOM];

    linePaint.setColor(borderColor);
    canvas.drawLine(0, 0, 0, chartView.getContentHeight(), linePaint);

    linePaint.setColor(lineColor);
    for (int i = 1; i < VERTICAL_LINE_NUMBER; i++) {
      float x = (i / (float) VERTICAL_LINE_NUMBER) * chartView.getWidth();
      canvas.drawLine(x, 0, x, chartView.getContentHeight(), linePaint);
    }

    linePaint.setColor(borderColor);
    canvas.drawLine(
        chartView.getWidth() - 1,
        0,
        chartView.getWidth() - 1,
        chartView.getContentHeight(),
        linePaint);
  }