コード例 #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
  @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);
  }
コード例 #3
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);
  }