コード例 #1
0
  @Override
  public void renderGridLines(Canvas c) {

    if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled()) return;

    float[] position = new float[] {0f, 0f};

    mGridPaint.setColor(mXAxis.getGridColor());
    mGridPaint.setStrokeWidth(mXAxis.getGridLineWidth());

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i < mMaxX; i += mXAxis.mAxisLabelModulus) {

      position[0] = i * step + i * bd.getGroupSpace() - 0.5f;

      mTrans.pointValuesToPixel(position);

      if (mViewPortHandler.isInBoundsX(position[0])) {

        c.drawLine(
            position[0],
            mViewPortHandler.offsetTop(),
            position[0],
            mViewPortHandler.contentBottom(),
            mGridPaint);
      }
    }
  }
コード例 #2
0
  /**
   * draws the x-labels on the specified y-position
   *
   * @param pos
   */
  @Override
  protected void drawLabels(Canvas c, float pos) {

    // pre allocate to save performance (dont allocate in loop)
    float[] position = new float[] {0f, 0f};

    BarData bd = mChart.getData();
    int step = bd.getDataSetCount();

    for (int i = mMinX; i <= mMaxX; i += mXAxis.mAxisLabelModulus) {

      position[0] = i * step + i * bd.getGroupSpace() + bd.getGroupSpace() / 2f;

      // consider groups (center label for each group)
      if (step > 1) {
        position[0] += ((float) step - 1f) / 2f;
      }

      mTrans.pointValuesToPixel(position);

      if (mViewPortHandler.isInBoundsX(position[0]) && i >= 0 && i < mXAxis.getValues().size()) {

        String label = mXAxis.getValues().get(i);
        int color = mXAxis.getTextColor(i);
        mAxisLabelPaint.setColor(color);

        if (mXAxis.isAvoidFirstLastClippingEnabled()) {

          // avoid clipping of the last
          if (i == mXAxis.getValues().size() - 1) {
            float width = Utils.calcTextWidth(mAxisLabelPaint, label);

            if (width > mViewPortHandler.offsetRight() * 2
                && position[0] + width > mViewPortHandler.getChartWidth()) position[0] -= width / 2;

            // avoid clipping of the first
          } else if (i == 0) {

            float width = Utils.calcTextWidth(mAxisLabelPaint, label);
            position[0] += width / 2;
          }
        }

        c.drawText(label, position[0], pos, mAxisLabelPaint);
      }
    }
  }
コード例 #3
0
  /**
   * Transforms an List of Entry into a float array containing the x and y values transformed with
   * all matrices for the BARCHART.
   *
   * @param entries
   * @param dataSet the dataset index
   * @return
   */
  public float[] generateTransformedValuesHorizontalBarChart(
      List<? extends Entry> entries, int dataSet, BarData bd, float phaseY) {

    float[] valuePoints = new float[entries.size() * 2];

    int setCount = bd.getDataSetCount();
    float space = bd.getGroupSpace();

    for (int j = 0; j < valuePoints.length; j += 2) {

      Entry e = entries.get(j / 2);

      // calculate the x-position, depending on datasetcount
      float x = e.getXIndex() + (j / 2 * (setCount - 1)) + dataSet + space * (j / 2) + space / 2f;
      float y = e.getVal();

      valuePoints[j] = y * phaseY;
      valuePoints[j + 1] = x;
    }

    pointValuesToPixel(valuePoints);

    return valuePoints;
  }